Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Dear Monks, Have created multiple files from one file ...

by Athanasius (Archbishop)
on Dec 31, 2014 at 17:03 UTC ( [id://1111850]=note: print w/replies, xml ) Need Help??


in reply to Dera Monks, Have create multiple file from one file now I want to match a pattern in each file at the same time do the replacement with adding one to the match pattern.

Hello hemantjsr,

Like Laurent_R, I don’t understand what you are trying to do. However, in the code posted I do notice a major problem in the use of variables. First, in the lines:

foreach my $line (@lines) { $line = $_;

$_ is undefined, so you are immediately deleting the contents of $line and replacing them with undef. (And the line would accomplish nothing, anyway, even if $_ did contain the next element of @lines, as that element has already been stored in $line via the foreach statement.)

Second, in the lines:

$line[0] =~ s~/4947000219/\K(4947000210+)~$1+$n~e; $line[1] =~ s{:20140924105028\K(\d+)}{

you are accessing the first and second elements of the array @line. But as this array has never been declared, the substitutions have nothing to work on. Please note that the array @line is an entirely different variable from the scalar $line. (I notice that you do declare a variable my $lines, but that variable is never used.) If you begin your script with:

use strict;

this will provide some (but not all) of the help you need to identify errors of this kind. See also Perl variable types and perldata.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Dear Monks, Have created multiple files from one file ...
by hemantjsr (Initiate) on Jan 01, 2015 at 18:06 UTC

    Done the changes in code, although am not getting any error but interpolation not happeningg

      Maybe you should add some debugging prints to see whether $line[0] and $line[1] are actually getting their replacements?

      Maybe the input data does not match what you expect?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-19 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found