[lug] Perl question: how to print embedded metacharacters

Jeffrey Haemer jeffrey.haemer at gmail.com
Wed Nov 25 09:17:50 MST 2009


Chip,

Okay.  Would something like this be good enough?


#!/usr/bin/perl

while (<>) {
  $_=` printf "$_" `;
  print;
}




On Wed, Nov 25, 2009 at 9:06 AM, Chip Atkinson <chip at pupman.com> wrote:

> No, unfortunately.
>
> The problem is that the script reads the string in from the command file,
> so I need to interpret the string before printing it.  Here's another
> example:
> ---------------------
> chip at chip-desktop:~$ cat try2.pl
> #!/usr/bin/perl
>
> #my $kw = 'abc\ndef';
> #my $nv = "${\($kw)}";
>
> while (<>) {
>  print "$_";
> }
> chip at chip-desktop:~$ echo 'abc\ndef' | ./try2.pl
> abc\ndef
> chip at chip-desktop:~$
> ---------------------------------
> In a sense, I need the opposite of quotemeta -- something that takes in a
> string and does the metacharacter replacements.
>
> I know that something like
> while (<>) {
>  s/\\n/\n/g;
>  # etc. for all metacharacter sequences...
>  print;
> }
>
> would work but I wanted to avoid the "etc. for all metacharacter
> sequences"
>
> Hopefully that's more understandable.
>
> Chip
>
> On Wed, 25 Nov 2009, Jeffrey Haemer wrote:
>
> > Chip,
> >
> > Can you do this instead?
> >
> > my $kw = "abc\ndef";
> >
> > If not, can you explain in enough detail that I can try again? :-)
> >
> > On Wed, Nov 25, 2009 at 8:29 AM, Chip Atkinson <chip at pupman.com> wrote:
> >
> > > Greetings,
> > >
> > > I'm working on a perl script that reads strings from a configuration
> file
> > > and prints them out.  What I'd like to be able to do is have any
> embedded
> > > metacharacters interpreted but I'd like to avoid doing the
> substitutions
> > > myself.
> > >
> > > For example, here is a little script to emulate the problem:
> > >
> > > #!/usr/bin/perl
> > >
> > > my $kw = 'abc\ndef';
> > >
> > > print "$kw";
> > > ----------------------
> > > the output is
> > > abc\ndef
> > >
> > > What I want is
> > > abc
> > > def
> > >
> > > --------------
> > > I tried to jfgi but no joy.
> > >
> > > Thanks in advance.
> > >
> > > Chip
> > >
> > > _______________________________________________
> > > Web Page:  http://lug.boulder.co.us
> > > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> > > Join us on IRC: lug.boulder.co.us port=6667 channel=#hackingsociety
> > >
> >
> >
> >
> > --
> > Click to Call Me Now! --
> > http://seejeffrun.blogspot.com/2009/09/call-me-now.html
> >
> > Jeffrey Haemer <jeffrey.haemer at gmail.com>
> > 720-837-8908 [cell],  @goyishekop [twitter]
> > http://www.youtube.com/user/goyishekop [vlog]
> >
>
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#hackingsociety
>



-- 
Click to Call Me Now! --
http://seejeffrun.blogspot.com/2009/09/call-me-now.html

Jeffrey Haemer <jeffrey.haemer at gmail.com>
720-837-8908 [cell],  @goyishekop [twitter]
http://www.youtube.com/user/goyishekop [vlog]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20091125/a21280d7/attachment.html>


More information about the LUG mailing list