Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Text File Problem

by buckaduck (Chaplain)
on Nov 06, 2002 at 22:10 UTC ( [id://210928]=note: print w/replies, xml ) Need Help??


in reply to Text File Problem

# Your code $_ =~ /^(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?)\*(.*?) +\*(.*?)\*(.*?)$/; my $value1=$1;

That is a very complicated way of doing what you really want, which is probably this:

# My code my ($value1) = split /\*/;

Next problem:

# Your code unless($value1 ne $ag) { s/$value1/$ag/g; $save_list=$save_list.$_; }
The s/// substitution is useless. This block of code only executes when $value1 equals $ag. So you're replacing the value with itself! I think you want if() rather than unless(). And you're probably right about removing the /g flag.

While we're at it, your $value1 could have special regex characters, so you should protect them with \Q..\E syntax:

# My code if ($value1 ne $ag) { s/\Q$value1\E/$ag/; $save_list=$save_list.$_; }

Update: Added \Q..\E recommendation.

buckaduck

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-18 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found