Regex basic question

V

Ved

Hi,

I have written a small program.



Things are fine when I am using functions like REVERSE (i.e. line 12).



But, having problem in Reg Exp statement (line 14).



------------------------------------------

#!usr/bin/perl
use strict; use warnings;

open(my $in, "<", "data2.munge") or die "error reading for reading";
open(my $out, ">", "data3.munge") or die "error creating for writting ";

my $rev =0;

while (<$in>) {
chomp;

#my $rev = reverse $_;
####Below line not working##
my $rev =~ s/dog/cat/;
print $out "$rev\n";

}
close $in;
close $out;
___________________________________________________



cat

dog dog

dog

cat

cat

dog dog

dog

cat

cat

dog dog

dog

cat
 
C

Charles DeRykus

...
my $rev =~ s/dog/cat/;
print $out "$rev\n";

}
...
--------------------------------------------------
------Error message-------------------------------
Use of uninitialized value $rev in concatenation (.) or string at test1.pl line 14, <IN> line 1.
Use of uninitialized value $rev in pattern match (m//) at test1.pl line 14, <IN> line 1.
..............and so on......

For regular expression basics, here're a couple of good sources:

perldoc perlretut
perldoc perlrequick

And for a more comprehensive look:

perldoc perlre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top