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

Re: Including special characters in a search and replace

by Caron (Friar)
on Jan 15, 2005 at 06:28 UTC ( [id://422467]=note: print w/replies, xml ) Need Help??


in reply to Including special characters in a search and replace

Use an index for your array of fields, combined with the /g modifier. This one works:

#!/usr/bin/perl -w use strict; my $line = "00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00," ."02,00,01,00,39,00,39,00,39,00,39,00,30,00,30,00,30,00,30,00," ."00,00,00,00,00,00,00,00,00,00,"; my @fields = (100, 101, 102, 103); my $index =0; $line =~ s/\b39\b/$fields[$index++]/g; print $line; __END__ output: 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,\ 00,02,00,01,00,100,00,101,00,102,00,103,00,30,00,30,00,30, \ 00,30,00,00,00,00,00,00,00,00,00,00,00,

See perlre for an explanation of the modifiers I have used here.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-24 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found