Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regex basic question

Reply
Thread Tools

Regex basic question

 
 
Ved
Guest
Posts: n/a
 
      07-29-2013
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

--------------------------------------------------
------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......
 
Reply With Quote
 
 
 
 
Charles DeRykus
Guest
Posts: n/a
 
      07-29-2013
On 7/28/2013 7:38 PM, Ved wrote:
> ...
> 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

--
Charles DeRykus


 
Reply With Quote
 
 
 
 
Ved
Guest
Posts: n/a
 
      08-01-2013
Thanks Guys. That helped
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
basic Regex question Greg Hauptmann Ruby 2 09-17-2008 02:03 AM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
Java regex imposture re: Perl regex compatibility a_c_Attlee@yahoo.com Java 2 05-06-2005 12:16 AM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments