Re: regexp with $ARGV
On Mon, 5 Nov 2001, Martin Karlsson wrote: Thanks a lot for your help and your time! I think I've got it solved now. You're welcome. : Could any of you recommend a good book for (learning) Perl? There seems to be quite a few to choose from... Oddly enough, that's what it's called: _Learning Perl_ http://www.oreilly.com/catalog/lperl3/ It's by Randal Schwartz Tom Phoenix. The target audience is people who already have basic programming knowledge and just need to learn Perl. However, I've heard people say that it also served as a good introduction to programming in general. Dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
regexp with $ARGV
Could anyone please show me the way to think here? If I execute a script with an argument, e.g monkey, then monkey will be found in $ARGV[0]. If I then want to highlight the word monkey by putting it in parentheses, i thought something like s/$ARGV[0]/\($ARGV[0]\)/g would do the trick; however it won't. Thanks, -- Martin Karlsson [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: regexp with $ARGV
If you only want to place parens around the input, then you can just place it parans like: $ARGV[0] = '(' . $ARGV[0] . ')'; In your original code, you want to work with $ARGV[0] but the regex w/o inputs assumes: $_ =~ s/$ARGV[0]/\($ARGV[0]\)/g; which is not what you are after. If you really want the regex then: $ARGV[0] =~ s/$ARGV[0]/\($ARGV[0]\)/g; would work for you. Wags ;) -Original Message- From: Martin Karlsson [mailto:[EMAIL PROTECTED]] Sent: Sunday, November 04, 2001 03:54 To: [EMAIL PROTECTED] Subject: regexp with $ARGV Could anyone please show me the way to think here? If I execute a script with an argument, e.g monkey, then monkey will be found in $ARGV[0]. If I then want to highlight the word monkey by putting it in parentheses, i thought something like s/$ARGV[0]/\($ARGV[0]\)/g would do the trick; however it won't. Thanks, -- Martin Karlsson [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp with $ARGV
Hi! Thanks for your help, I really appreciate it. However, I just don't seem able to figure out how to do it; please have a look at the attached script. Perhaps you can find some stupid rookie-mistake in it which could explain why it's not working the way I want :-). Have a nice week, /Martin * Wagner-David ([EMAIL PROTECTED]) wrote: If you only want to place parens around the input, then you can just place it parans like: $ARGV[0] = '(' . $ARGV[0] . ')'; In your original code, you want to work with $ARGV[0] but the regex w/o inputs assumes: $_ =~ s/$ARGV[0]/\($ARGV[0]\)/g; which is not what you are after. If you really want the regex then: $ARGV[0] =~ s/$ARGV[0]/\($ARGV[0]\)/g; would work for you. Wags ;) -Original Message- From: Martin Karlsson [mailto:[EMAIL PROTECTED]] Sent: Sunday, November 04, 2001 03:54 To: [EMAIL PROTECTED] Subject: regexp with $ARGV Could anyone please show me the way to think here? If I execute a script with an argument, e.g monkey, then monkey will be found in $ARGV[0]. If I then want to highlight the word monkey by putting it in parentheses, i thought something like s/$ARGV[0]/\($ARGV[0]\)/g would do the trick; however it won't. Thanks, -- Martin Karlsson [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Martin Karlsson [EMAIL PROTECTED] 11.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp with $ARGV
Martin, I'm not entirely clear on what you're trying to do here, so if this doesn't help, let me know and I'll try again. I think the problem is that you're doing this: s/$ARGV[0]/\($ARGV[0]\)/g ...when you want to affect $ARGV[0]. But remember that s/// and m// are, by default, applied to the contents of the $_ variable. So, when Perl sees that line of code above, it effectively rewrites it to be: $_ =~ s/$ARGV[0]/\($ARGV[0]\)/g; Which, in English, means something like this: Go through the string stored in the $_ variable. Look for a substring which is identical to the string stored in $ARGV[0]. If you find it, replace it with that same string with parens around it. Finally, because there is a 'g' option on the operation, do not stop after finding the first match; continue through the contents of $_ and replace any other matches you find. I think what you want instead is this: $ARGV[0] = ($ARGV[0]); Dave On Sun, 4 Nov 2001, Martin Karlsson wrote: Could anyone please show me the way to think here? If I execute a script with an argument, e.g monkey, then monkey will be found in $ARGV[0]. If I then want to highlight the word monkey by putting it in parentheses, i thought something like s/$ARGV[0]/\($ARGV[0]\)/g would do the trick; however it won't. Thanks, -- Martin Karlsson [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: regexp with $ARGV
At 11:38 AM 11/4/01 -0800, Wagner-David wrote: If you only want to place parens around the input, then you can just place it parans like: $ARGV[0] = '(' . $ARGV[0] . ')'; Somewhat clearer: $ARGV[0] = ($ARGV[0]); In your original code, you want to work with $ARGV[0] but the regex w/o inputs assumes: $_ =~ s/$ARGV[0]/\($ARGV[0]\)/g; which is not what you are after. If you really want the regex then: $ARGV[0] =~ s/$ARGV[0]/\($ARGV[0]\)/g; would work for you. Not always, if $ARGV[0] contained regex metacharacters. And those \s are unnecessary. Much better: $ARGV[0] =~ s/(.*)/($1)/s; -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]