Perl
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: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Thursday, December 05, 2002 1:56 AM
To: Paul Kraus
Cc: [email protected]
Subject: Re: Perl
Quoted 5 lines · Paul Kraus
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 [email protected] 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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Quoted 1 line · Paul Kraus
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.
Quoted 7 lines
$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.
Quoted 2 lines
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 [email protected]
-------------------------------------------------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
A message that is not in the archive (sent off-list or not yet received): 01bb01c29bcd$3eba1a60$64fea8c0@pkrausxp
Quoted 5 lines · Paul Kraus
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 [email protected]
-------------------------------------------------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs