
s660117
User
Oct 20, 2012, 11:48 AM
Post #18 of 31
(13870 views)
|
Re: [FishMonger] Using \? in a variable
[In reply to]
|
Can't Post
|
|
Thanks for all your help, FishMonger, but I still have a question or two. I have amended my opening code as follows -- #! /usr/bin/perl -w use strict; use warnings; use Getopt::Long; use File::Find; use Data::Dumper; my ($option, $dir, $str, $file); GetOptions ( 'd=s' => \$dir, 'o=s' => \$option, 's' => \$str, 'f' => \$file, ); die usage() unless ($dir and $option and ($str or $file)); sub usage { print "Usage: $0 -d <dir> -o <option> -s -f\n\n", "Example: $0 -d . -o 'some *? option' -s -f\n\n" } $str = quotemeta($str); print Dumper ($option, $dir, $file, $str); -d $dir || die "Directory not found. Terminating $!"; print "Now scanning $dir for \"$str\"\n"; exit;
1) Now when I execute perl my_script -p -s -d '.' -s "ZZZ" with $str and $file defined as booleans, the Print Dumper line prints -- $VAR1 = '-s'; $VAR2 = '.'; $VAR3 = undef; $VAR4 = '1'; Now scanning . for "1", where the value of $str is '1'. If I change those GetOptions to strings, I get -- $VAR1 = '-s'; $VAR2 = '.'; $VAR3 = undef; $VAR4 = 'ZZZ'; Now scanning . for "ZZZ", and the value of $str is available for use. 2) When I execute perl mygrep_pg -o -s -d '.' -s ???, without quotes around the string, I still see the first member in the directory whose name is three characters long -- $VAR1 = '-s'; $VAR2 = '.'; $VAR3 = undef; $VAR4 = 'INC'; Now scanning . for "INC". I would love to understand what is happening here. 3) When I execute perl mygrep_pg -o -s -d '.' -s "???", with quotes, I see -- $VAR1 = '-s'; $VAR2 = '.'; $VAR3 = undef; $VAR4 = '\\?\\?\\?'; Now scanning . for "\?\?\?". So, the final option works, in spite of the double backslashes. Once again, thanks for your help, although I remain clueless as to how @ARGV is handling an unquoted question mark. s660117 (And sorry for the bold type; I am having a problem turning it off.)
|