Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: ".." inside a variable Message-ID: <1991May10.162039.23675@jpl-devvax.jpl.nasa.gov> Date: 10 May 91 16:20:39 GMT References: <1180016@hpcc01.HP.COM> <1362@appli.se> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 52 In article <1362@appli.se> niklas@appli.se (Niklas Hallqvist) writes: : okamoto@hpcc01.HP.COM (Jeff Okamoto) writes: : : >I'm trying to get the .. construct to work when it is passed in as a command : >line argument. What I am having trouble with is getting the .. to properly : >expand. I've tried a bunch of ways to force the result into an array context, : >but I'm obviously doing something wrong. : : >I've tried a number of variations on the following, to no avail: : : > $a = "'A0'..'A9'"; # Eventually will be shift(@ARGV); : : > eval "\@b = (\$a)"; : : >Can anyone offer any suggestions? : : What version of perl are you running? On my 4.003 the following : perl-script works allright: : : #!/local/bin/perl : $range = shift; : eval "@array = $range"; : print "@array\n"; : : When invoked as: : foo "'A1'..'A9'" : : it prints: : A1 A2 A3 A4 A5 A6 A7 A8 A9 : : That's what you wanted, wasn't it? This just happens to work because @array inside double quotes is grandfathered not to work unless @array is referenced outside of double quotes, to protect ancient scripts in which @array was never interpolated. You can prove this to yourself by adding @array; at the end of your script--it stops working. It's better to backwhack the @array reference in the eval: eval "\@array = ($range)"; die $@ if $@; If you put the parens around $range like that, you can also invoke it as foo "A1..A9,A13" And checking $@ after evaluating user supplied strings will save a lot of aggravation in the long run. Larry