Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Matching @ in string

by lima1 (Curate)
on Nov 22, 2007 at 13:22 UTC ( #652363=note: print w/replies, xml ) Need Help??


in reply to Matching @ in string

You have introduced the array @t which is interpolated. So you have to quote the @ (or write q{h@t}).
perl -e 'if ("h\@t" =~ /(\@)/ ) { print $1 }'
Example for an array interpolation:
#!/usr/bin/perl use strict; use warnings; my @friends = ('Margaret', 'Richard', 'Carolyn', 'Rohan', 'Cathy', 'Yukiko'); print "Friends: @friends\n";

Replies are listed 'Best First'.
Re^2: Matching @ in string
by loris (Hermit) on Nov 22, 2007 at 13:49 UTC

    OK, so I was missing something obvious.

    But if I don't want to modify the string by escaping the @ and I want to run program as a one-liner, how do I do it if I can't escape the single quotes as you point out here?

    Thanks,

    loris


    "It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ." (from "Slow Loris" by Alexis Deacon)
      ... don't want to modify the string by escaping the @ and I want to run program as a one-liner, how do I do it if I can't escape the single quotes

      Try: ...

      perl -e "print 'h@t'=~ /\@/g"
      or even
      echo 'h@t' | perl -ne 'print /\@/g'

      ... depending on the type of problem you are about to solve.

      Regards

      mwa

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://652363]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2021-04-19 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?