jes@mbio.med.upenn.edu (Joe Smith) (08/23/90)
Is there function call or idiom to get Perl to do double-quote expansion on the contents of a string? I'm still a little squeamish using 'eval...', at least as I understand, it won't do what I want. Why, you ask? Well, I wanted to use perl to do some simple macro processing on information read from a file. If perl would do the replacement, it would save scanning the lines explicitly in my code. A contrived example which (when run) demonstrates the problem: #!/bin/sh echo 'The time is now $TIME' | perl -ne ' sub showtime { join("-",@_); } $TIME = &showtime(localtime(time)); print " I want this to print The time is now $TIME, not $_";' Any suggestions? <Joe -- Joe Smith University of Pennsylvania jes@mbio.med.upenn.edu Dept. of Biochemistry and Biophysics (215) 898-8348 Philadelphia, PA 19104-6059
merlyn@iwarp.intel.com (Randal Schwartz) (08/24/90)
In article <JES.90Aug22174345@mbio.med.upenn.edu>, jes@mbio (Joe Smith) writes: | | Is there function call or idiom to get Perl to do double-quote | expansion on the contents of a string? I'm still a little squeamish | using 'eval...', at least as I understand, it won't do what I want. | | Why, you ask? Well, I wanted to use perl to do some simple macro | processing on information read from a file. If perl would do the | replacement, it would save scanning the lines explicitly in my code. | | A contrived example which (when run) demonstrates the problem: | | #!/bin/sh | echo 'The time is now $TIME' | perl -ne ' | | sub showtime { join("-",@_); } | | $TIME = &showtime(localtime(time)); | | print " | I want this to print | The time is now $TIME, | not | $_";' | | | Any suggestions? | | <Joe | -- | Joe Smith | University of Pennsylvania jes@mbio.med.upenn.edu | Dept. of Biochemistry and Biophysics (215) 898-8348 | Philadelphia, PA 19104-6059 #!/bin/sh echo 'The time is now $TIME' | perl -ne ' sub showtime { join("-",@_); } $TIME = &showtime(localtime(time)); s/\$\w+/eval $&/eg; ## insert this print ' Simple, short. Yeah, I used the ugly 'eval' word. Oh well. $_='print substr($_,25,25); "Just another Perl hacker,";'; eval -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/