Linux Newbie help
 help / color / mirror / Atom feed
* FW: Perl
@ 2002-12-04 18:27 Paul Kraus
  2002-12-04 19:33 ` Ray Olszewski
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Kraus @ 2002-12-04 18:27 UTC (permalink / raw)
  To: linux-newbie

Its perl hence the subject :)

$5 is the 5th memory of a regular expression. The second statement then
uses a regular expression to replace " " with "\ " to correct paths.

$5=Somefolder/some secondfolder
$path would get Somefolder/some\ secondfolder.

I want to condsense this into one statement. I am probably off topic
here but I have seen others post about basic programming issues.

Thanks,
Paul

-----Original Message-----
From: linux-newbie-owner@vger.kernel.org
[mailto:linux-newbie-owner@vger.kernel.org] On Behalf Of ichi@ihug.co.nz
Sent: Thursday, December 05, 2002 1:56 AM
To: Paul Kraus
Cc: linux-newbie@vger.kernel.org
Subject: Re: Perl


Paul Kraus wrote:
> 
> How can I make this assignment in one statement.
> I know its going to be something easy.
> $path=$5;
> $path=~s/ /\\ /g;

I don't understand.  Is this part of a bash script?
It looks like you a trying to assign the fifth parameter 
(path=$5) to a variable named path (which BTW is not the
PATH) and then manipulate it in some way (something to do 
with \ I think).

Perhaps this is some language that I am unfamiliar with?
If so, I apologize.  However, if is bash, I suggest you 
explain in words what you want to do, and I will try to
script it.

Cheers,
Steven

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in the body of a message to majordomo@vger.kernel.org More majordomo
info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FW: Perl
  2002-12-04 18:27 FW: Perl Paul Kraus
@ 2002-12-04 19:33 ` Ray Olszewski
       [not found]   ` <01bb01c29bcd$3eba1a60$64fea8c0@pkrausxp>
  0 siblings, 1 reply; 4+ messages in thread
From: Ray Olszewski @ 2002-12-04 19:33 UTC (permalink / raw)
  To: linux-newbie

At 01:27 PM 12/4/02 -0500, Paul Kraus wrote:
>Its perl hence the subject :)

Like (apparently) ichi, I missed this in the Subject: line when you first 
posted it. Perhaps there's a lesson there ... it pays to write a few more 
words than the bare minimum your message needs, to make it *easy* (not just 
*possible*) for people to understand your question. This is not IRC, after 
all ... we can tolerate the extra space for a few more words fairly easily.


>$5 is the 5th memory of a regular expression. The second statement then
>uses a regular expression to replace " " with "\ " to correct paths.
>
>$5=Somefolder/some secondfolder
>$path would get Somefolder/some\ secondfolder.
>
>I want to condsense this into one statement.

Why? This is not nagging, but a real question. I ask because while it 
should be possible to combine these two statments into one (just search on 
"obfuscated Perl" to see both how easy this is and how unreadable the 
resulting code can be), doing so probably will not make the program run any 
faster, and it will almost surely make it harder to read (and, hence, 
maintain).

So it would help to know your purpose in wanting to combine these 
statements. If you are looking to save time or memory, I doubt that 
modifying the source will help, at least not as long as you need $5 to 
continue to hold the unedited version of thestring while $path contains the 
edited version. As it is, you've written it just the way I would.

>I am probably off topic
>here but I have seen others post about basic programming issues.

Not off topic at all; these sorts of questions come up regularly, as you've 
noted.


--
-------------------------------------------"Never tell me the odds!"--------
Ray Olszewski					-- Han Solo
Palo Alto, California, USA			  ray@comarre.com
-------------------------------------------------------------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: FW: Perl
@ 2002-12-04 19:42 Paul Kraus
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Kraus @ 2002-12-04 19:42 UTC (permalink / raw)
  To: linux-newbie

Odd we looked at the same problem and came up with completely opposing
conclusions. My attempt to combine them was for the sake of readability.
I know Perl has a 1000 ways to write the same statement. I thought there
would be a better more readable way. Sort of like Paul = + 1 can be
written Paul += Paul. The second of which is easier for me to look at. 

-----Original Message-----
From: linux-newbie-owner@vger.kernel.org
[mailto:linux-newbie-owner@vger.kernel.org] On Behalf Of Ray Olszewski
Sent: Wednesday, December 04, 2002 2:34 PM
To: linux-newbie@vger.kernel.org
Subject: Re: FW: Perl


At 01:27 PM 12/4/02 -0500, Paul Kraus wrote:
>Its perl hence the subject :)

Like (apparently) ichi, I missed this in the Subject: line when you
first 
posted it. Perhaps there's a lesson there ... it pays to write a few
more 
words than the bare minimum your message needs, to make it *easy* (not
just 
*possible*) for people to understand your question. This is not IRC,
after 
all ... we can tolerate the extra space for a few more words fairly
easily.


>$5 is the 5th memory of a regular expression. The second statement then
>uses a regular expression to replace " " with "\ " to correct paths.
>
>$5=Somefolder/some secondfolder
>$path would get Somefolder/some\ secondfolder.
>
>I want to condsense this into one statement.

Why? This is not nagging, but a real question. I ask because while it 
should be possible to combine these two statments into one (just search
on 
"obfuscated Perl" to see both how easy this is and how unreadable the 
resulting code can be), doing so probably will not make the program run
any 
faster, and it will almost surely make it harder to read (and, hence, 
maintain).

So it would help to know your purpose in wanting to combine these 
statements. If you are looking to save time or memory, I doubt that 
modifying the source will help, at least not as long as you need $5 to 
continue to hold the unedited version of thestring while $path contains
the 
edited version. As it is, you've written it just the way I would.

>I am probably off topic
>here but I have seen others post about basic programming issues.

Not off topic at all; these sorts of questions come up regularly, as
you've 
noted.


--
-------------------------------------------"Never tell me the
odds!"--------
Ray Olszewski					-- Han Solo
Palo Alto, California, USA			  ray@comarre.com
------------------------------------------------------------------------
-------

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in the body of a message to majordomo@vger.kernel.org More majordomo
info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: FW: Perl
       [not found]   ` <01bb01c29bcd$3eba1a60$64fea8c0@pkrausxp>
@ 2002-12-04 20:03     ` Ray Olszewski
  0 siblings, 0 replies; 4+ messages in thread
From: Ray Olszewski @ 2002-12-04 20:03 UTC (permalink / raw)
  To: linux-newbie

At 02:42 PM 12/4/02 -0500, Paul Kraus wrote:
>Odd we looked at the same problem and came up with completely opposing
>conclusions. My attempt to combine them was for the sake of readability.
>I know Perl has a 1000 ways to write the same statement. I thought there
>would be a better more readable way. Sort of like Paul = + 1 can be
>written Paul += Paul. The second of which is easier for me to look at.

Not in Perl. These two operations do different things, and neither does 
what I suspect you think they both do (increment Paul by 1). Example below:

#!/usr/bin/perl

$paul = 23      ;

#!/usr/bin/perl

$paul = 23      ;
$paul = +1      ;

$paul2 = 23     ;
$paul2 += $paul2        ;

print "paul=$paul but paul2 =$paul2\n"  ;
#EOP

ray@waverly:~$ ./testme2.pl
paul=1 but paul2 =46

This offers a nice illustration of why I dislike most "shortcut" syntax. I 
even usually prefer to write $paul = $paul + 1 rather than its equivalent 
$paul++, except in highly conventionalized uses like "for" statements. 
YMMV, of course.

BTW, Alan's suggestion won't work either (either exactly as proposed or in 
the easy variants I could try ... though Perl is wonky enough that *some* 
variation on his idea might work). Two reasons:

1. $5 is a read-only variable so you can't apply the =~s operator to it.

2. In general, $a = $b = $c assigns to $a the return code from the 
operation $b = $c --  either 1 for success or 0 for failure -- not the 
value in $c.

Another nice example of why I hate "shortcut" syntax. Boring is better.


--
-------------------------------------------"Never tell me the odds!"--------
Ray Olszewski					-- Han Solo
Palo Alto, California, USA			  ray@comarre.com
-------------------------------------------------------------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-12-04 20:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-04 18:27 FW: Perl Paul Kraus
2002-12-04 19:33 ` Ray Olszewski
     [not found]   ` <01bb01c29bcd$3eba1a60$64fea8c0@pkrausxp>
2002-12-04 20:03     ` Ray Olszewski
  -- strict thread matches above, loose matches on Subject: below --
2002-12-04 19:42 Paul Kraus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox