Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: How do i replace one variable with another after searching for a pattern

by AppleFritter (Vicar)
on Jul 31, 2014 at 18:27 UTC ( [id://1095790]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How do i replace one variable with another after searching for a pattern
in thread How do i replace one variable with another after searching for a pattern

Even easier. Same as above, but the regex simplifies to:

s/<([0-9A-F]+)>/hex($1)/eg;
  • Comment on Re^3: How do i replace one variable with another after searching for a pattern
  • Download Code

Replies are listed 'Best First'.
Re^4: How do i replace one variable with another after searching for a pattern
by Niklaus Mikaelson (Initiate) on Jul 31, 2014 at 18:32 UTC
    stummala@sa-mua01:/home/stummala/scripts$./samp2 Can't locate feature.pm in @INC (@INC contains: /home/gsapan/perl5/lib +/perl5/sun4-solaris-thread-multi /home/gsapan/perl5/lib/perl5/x86_64- +linux-thread-multi /home/gsapan/perl5/lib/perl5 /usr/lib64/perl5/site +_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 +/usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib64/pe +rl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor +_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64- +linux-thread-multi /usr/lib/perl5/5.8.8 .) at ./samp2 line 4. BEGIN failed--compilation aborted at ./samp2 line 4.

      Ah, you're using an ancient perl. Simply leave out the use feature qw/say/; line, and replace say; in the loop body with a print statement:

      while(<DATA>) { chomp; s/<([0-9A-F]+)>/hex($1)/eg; print "$_\n"; }

      Actually, you could probably also get away with not chomping your input in the first place here:

      while(<DATA>) { s/<([0-9A-F]+)>/hex($1)/eg; print; }

      And at this point, assuming you merely want to output the results and do nothing further with them in this particular script, the whole script can be turned into a oneliner you can directly enter on the command line. Using perl's -p switch (see perlrun):

      $ perl -pe 's/<([0-9A-F]+)>/hex($1)/eg' /home/stummala/a JDW-HP 1MVWV93V7j2Hxsa0Ag6 24:00:00 SUBJECT_EXACT _Did you160serve our +160country? -New VA Home.Loan Program_ JDW-HP 1MVWV98Ddd4fLsa0Ag6 24:00:00 SUBJECT_EXACT Did.you.serve_our co +untry? New-VA Home160Loan Program_ $

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-19 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found