Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

perl-beginner · Perl Beginners Mailing List

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 3765
  • Category: Perl
  • Founded: Aug 2, 1998
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

Advanced
Messages Help
Messages 26255 - 26286 of 27459   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#26255 From: "Amit Saxena" <learn.tech123@...>
Date: Tue Jul 8, 2008 12:31 pm
Subject: Re: [PBML] Can a substitute self-reference?
learn.tech123@...
Send Email Send Email
 
Hi

Not sure whether my version is more efficient / better or not (comments
awaited) :-

[root@111 ~]# cat v.pl
#! /usr/bin/perl

my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1, )";

print "\nstring is [$string]";

# $string =~ s/array\s\(\s(.*),\s\)/$1/;
$string =~ s/^([^(]*\(\s+)(.*?)(,\s+\))$/\2/g;

print "\nstring is [$string]";

print "\nHave a nice day !\n";

[root@111 ~]# perl v.pl

string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1, )]
string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
Have a nice day !
[root@111 ~]#

Regards,
Amit Saxena

On Tue, Jul 8, 2008 at 5:46 PM, hooyar66 <pcbcad@...> wrote:

>   --- In perl-beginner@yahoogroups.com <perl-beginner%40yahoogroups.com>,
> "Amit Saxena"
>
> <learn.tech123@...> wrote:
> >
> > It's working at my end though it does not seems to be an efficient way,
> >
> > [root@111 ~]# cat v.pl
> > #! /usr/bin/perl
> >
> > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 =>
> 1, )";
> >
> > print "\nstring is [$string]";
> >
> > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> >
> > print "\nstring is [$string]";
> >
> > print "\nHave a nice day !\n";
> >
> > [root@111 ~]# perl v.pl
> >
> > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1, )]
> > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > Have a nice day !
> > [root@111 ~]#
> >
> > Regards,
> > Amit Saxena
> >
> > On Tue, Jul 8, 2008 at 5:10 PM, hooyar66 <pcbcad@...> wrote:
> >
> > > I want to remove from the string below - "array ( " at the front and
> > > the ", )" at the end with a single substitute command.
> > >
> > > The following is what I have tried but doesn't work:
> > >
> > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 =>
> > > 1, )";
> > >
> > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > >
> > > I can do it with a couple of line - one for each end, but I was hoping
> > > it would be possible with one.
> > >
> > > Any help appreciated
> > >
> > > Thanks
> > > NJH
> > >
> > >
> > >
> >
> >
> > [Non-text portions of this message have been removed]
> >
>
> Very bizarre - it's not working for me: WIN XP, Activestate v5.8.8
>
> Can you recommend a more 'efficient way'?
>
> Thanks
>
>
>


[Non-text portions of this message have been removed]

#26256 From: "Thiago Nascimento" <nascimenthiago@...>
Date: Tue Jul 8, 2008 12:33 pm
Subject: Re: [PBML] Can a substitute self-reference?
nascimentoth...
Send Email Send Email
 
Another regex is:

$string =~ s/^\D*(\d.*\d)\D*$/$1/;

On Tue, Jul 8, 2008 at 9:31 AM, Amit Saxena <learn.tech123@...> wrote:

>   Hi
>
> Not sure whether my version is more efficient / better or not (comments
> awaited) :-
>
>
> [root@111 ~]# cat v.pl
> #! /usr/bin/perl
>
> my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1, )";
>
> print "\nstring is [$string]";
>
> # $string =~ s/array\s\(\s(.*),\s\)/$1/;
> $string =~ s/^([^(]*\(\s+)(.*?)(,\s+\))$/\2/g;
>
> print "\nstring is [$string]";
>
> print "\nHave a nice day !\n";
>
> [root@111 ~]# perl v.pl
>
> string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1, )]
> string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> Have a nice day !
> [root@111 ~]#
>
> Regards,
> Amit Saxena
>
> On Tue, Jul 8, 2008 at 5:46 PM, hooyar66
<pcbcad@...<pcbcad%40hotpop.com>>
> wrote:
>
> > --- In perl-beginner@yahoogroups.com
<perl-beginner%40yahoogroups.com><perl-beginner%
> 40yahoogroups.com>,
>
> > "Amit Saxena"
> >
> > <learn.tech123@...> wrote:
> > >
> > > It's working at my end though it does not seems to be an efficient way,
> > >
> > > [root@111 ~]# cat v.pl
> > > #! /usr/bin/perl
> > >
> > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 =>
> > 1, )";
> > >
> > > print "\nstring is [$string]";
> > >
> > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > >
> > > print "\nstring is [$string]";
> > >
> > > print "\nHave a nice day !\n";
> > >
> > > [root@111 ~]# perl v.pl
> > >
> > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1, )]
> > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > Have a nice day !
> > > [root@111 ~]#
> > >
> > > Regards,
> > > Amit Saxena
> > >
> > > On Tue, Jul 8, 2008 at 5:10 PM, hooyar66 <pcbcad@...> wrote:
> > >
> > > > I want to remove from the string below - "array ( " at the front and
> > > > the ", )" at the end with a single substitute command.
> > > >
> > > > The following is what I have tried but doesn't work:
> > > >
> > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 =>
> > > > 1, )";
> > > >
> > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > >
> > > > I can do it with a couple of line - one for each end, but I was
> hoping
> > > > it would be possible with one.
> > > >
> > > > Any help appreciated
> > > >
> > > > Thanks
> > > > NJH
> > > >
> > > >
> > > >
> > >
> > >
> > > [Non-text portions of this message have been removed]
> > >
> >
> > Very bizarre - it's not working for me: WIN XP, Activestate v5.8.8
> >
> > Can you recommend a more 'efficient way'?
> >
> > Thanks
> >
> >
> >
>
> [Non-text portions of this message have been removed]
>
>
>



--
Thiago Nascimento
perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
s/(..)(.)//;print substr$_,1,1;'
"...just because I don't know the meaning of my art, does not mean it has no
meaning..." S.D.


[Non-text portions of this message have been removed]

#26257 From: "hooyar66" <pcbcad@...>
Date: Tue Jul 8, 2008 1:01 pm
Subject: Re: [PBML] Can a substitute self-reference?
hooyar66
Send Email Send Email
 
--- In perl-beginner@yahoogroups.com, "Thiago Nascimento"
<nascimenthiago@...> wrote:
>
> Another regex is:
>
> $string =~ s/^\D*(\d.*\d)\D*$/$1/;
>
> On Tue, Jul 8, 2008 at 9:31 AM, Amit Saxena <learn.tech123@...> wrote:
>
> >   Hi
> >
> > Not sure whether my version is more efficient / better or not
(comments
> > awaited) :-
> >
> >
> > [root@111 ~]# cat v.pl
> > #! /usr/bin/perl
> >
> > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120
=> 1, )";
> >
> > print "\nstring is [$string]";
> >
> > # $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > $string =~ s/^([^(]*\(\s+)(.*?)(,\s+\))$/\2/g;
> >
> > print "\nstring is [$string]";
> >
> > print "\nHave a nice day !\n";
> >
> > [root@111 ~]# perl v.pl
> >
> > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 =>
1, )]
> > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > Have a nice day !
> > [root@111 ~]#
> >
> > Regards,
> > Amit Saxena
> >
> > On Tue, Jul 8, 2008 at 5:46 PM, hooyar66
<pcbcad@...<pcbcad%40hotpop.com>>
> > wrote:
> >
> > > --- In perl-beginner@yahoogroups.com
<perl-beginner%40yahoogroups.com><perl-beginner%
> > 40yahoogroups.com>,
> >
> > > "Amit Saxena"
> > >
> > > <learn.tech123@> wrote:
> > > >
> > > > It's working at my end though it does not seems to be an
efficient way,
> > > >
> > > > [root@111 ~]# cat v.pl
> > > > #! /usr/bin/perl
> > > >
> > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14,
120 =>
> > > 1, )";
> > > >
> > > > print "\nstring is [$string]";
> > > >
> > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > >
> > > > print "\nstring is [$string]";
> > > >
> > > > print "\nHave a nice day !\n";
> > > >
> > > > [root@111 ~]# perl v.pl
> > > >
> > > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120
=> 1, )]
> > > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > > Have a nice day !
> > > > [root@111 ~]#
> > > >
> > > > Regards,
> > > > Amit Saxena
> > > >
> > > > On Tue, Jul 8, 2008 at 5:10 PM, hooyar66 <pcbcad@> wrote:
> > > >
> > > > > I want to remove from the string below - "array ( " at the
front and
> > > > > the ", )" at the end with a single substitute command.
> > > > >
> > > > > The following is what I have tried but doesn't work:
> > > > >
> > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
14, 120 =>
> > > > > 1, )";
> > > > >
> > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > >
> > > > > I can do it with a couple of line - one for each end, but I was
> > hoping
> > > > > it would be possible with one.
> > > > >
> > > > > Any help appreciated
> > > > >
> > > > > Thanks
> > > > > NJH
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > [Non-text portions of this message have been removed]
> > > >
> > >
> > > Very bizarre - it's not working for me: WIN XP, Activestate v5.8.8
> > >
> > > Can you recommend a more 'efficient way'?
> > >
> > > Thanks
> > >
> > >
> > >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
>
>
>
> --
> Thiago Nascimento
> perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
> s/(..)(.)//;print substr$_,1,1;'
> "...just because I don't know the meaning of my art, does not mean
it has no
> meaning..." S.D.
>
>
> [Non-text portions of this message have been removed]
>

Thanks Thiago - I like! Seems my 'solution replication' problem is
elsewhere....

#26258 From: "hooyar66" <pcbcad@...>
Date: Tue Jul 8, 2008 2:05 pm
Subject: Re: [PBML] Can a substitute self-reference?
hooyar66
Send Email Send Email
 
--- In perl-beginner@yahoogroups.com, "hooyar66" <pcbcad@...> wrote:
>
> --- In perl-beginner@yahoogroups.com, "Thiago Nascimento"
> <nascimenthiago@> wrote:
> >
> > Another regex is:
> >
> > $string =~ s/^\D*(\d.*\d)\D*$/$1/;
> >
> > On Tue, Jul 8, 2008 at 9:31 AM, Amit Saxena <learn.tech123@> wrote:
> >
> > >   Hi
> > >
> > > Not sure whether my version is more efficient / better or not
> (comments
> > > awaited) :-
> > >
> > >
> > > [root@111 ~]# cat v.pl
> > > #! /usr/bin/perl
> > >
> > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120
> => 1, )";
> > >
> > > print "\nstring is [$string]";
> > >
> > > # $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > $string =~ s/^([^(]*\(\s+)(.*?)(,\s+\))$/\2/g;
> > >
> > > print "\nstring is [$string]";
> > >
> > > print "\nHave a nice day !\n";
> > >
> > > [root@111 ~]# perl v.pl
> > >
> > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 =>
> 1, )]
> > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > Have a nice day !
> > > [root@111 ~]#
> > >
> > > Regards,
> > > Amit Saxena
> > >
> > > On Tue, Jul 8, 2008 at 5:46 PM, hooyar66
> <pcbcad@<pcbcad%40hotpop.com>>
> > > wrote:
> > >
> > > > --- In perl-beginner@yahoogroups.com
> <perl-beginner%40yahoogroups.com><perl-beginner%
> > > 40yahoogroups.com>,
> > >
> > > > "Amit Saxena"
> > > >
> > > > <learn.tech123@> wrote:
> > > > >
> > > > > It's working at my end though it does not seems to be an
> efficient way,
> > > > >
> > > > > [root@111 ~]# cat v.pl
> > > > > #! /usr/bin/perl
> > > > >
> > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14,
> 120 =>
> > > > 1, )";
> > > > >
> > > > > print "\nstring is [$string]";
> > > > >
> > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > >
> > > > > print "\nstring is [$string]";
> > > > >
> > > > > print "\nHave a nice day !\n";
> > > > >
> > > > > [root@111 ~]# perl v.pl
> > > > >
> > > > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120
> => 1, )]
> > > > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > > > Have a nice day !
> > > > > [root@111 ~]#
> > > > >
> > > > > Regards,
> > > > > Amit Saxena
> > > > >
> > > > > On Tue, Jul 8, 2008 at 5:10 PM, hooyar66 <pcbcad@> wrote:
> > > > >
> > > > > > I want to remove from the string below - "array ( " at the
> front and
> > > > > > the ", )" at the end with a single substitute command.
> > > > > >
> > > > > > The following is what I have tried but doesn't work:
> > > > > >
> > > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
> 14, 120 =>
> > > > > > 1, )";
> > > > > >
> > > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > >
> > > > > > I can do it with a couple of line - one for each end, but
I was
> > > hoping
> > > > > > it would be possible with one.
> > > > > >
> > > > > > Any help appreciated
> > > > > >
> > > > > > Thanks
> > > > > > NJH
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > [Non-text portions of this message have been removed]
> > > > >
> > > >
> > > > Very bizarre - it's not working for me: WIN XP, Activestate v5.8.8
> > > >
> > > > Can you recommend a more 'efficient way'?
> > > >
> > > > Thanks
> > > >
> > > >
> > > >
> > >
> > > [Non-text portions of this message have been removed]
> > >
> > >
> > >
> >
> >
> >
> > --
> > Thiago Nascimento
> > perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
> > s/(..)(.)//;print substr$_,1,1;'
> > "...just because I don't know the meaning of my art, does not mean
> it has no
> > meaning..." S.D.
> >
> >
> > [Non-text portions of this message have been removed]
> >
>
> Thanks Thiago - I like! Seems my 'solution replication' problem is
> elsewhere....
>

OK I've isolated my problem - I really would appreciate some help
understanding what the problem is.

My String (each character in square brackets) is really this, note the
'extra' whitespace:

[a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][
][8][9][ ][=][>][ ][1][3][,][ ][ ][ ][8][8][ ][=][>][ ][6][,][ ][ ][
][9][0][ ][=][>][ ][1][4][,][ ][ ][ ][1][2][0][ ][=][>][ ][1][,][ ][)]

If I use the following command:

$return =~ s/(^\D*\d.*)/$1/;

I get this:

[a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,]

Surely I ought to get the whole string as '.*' means any old junk?

If I use the following command:

$string =~ s/(^\D*\d.*\s*)/$1/;

I get this:

[a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][ ]

So the problem seems to be that '.*' has an issue with multiple
whitespace... or something!

#26259 From: "Amit Saxena" <learn.tech123@...>
Date: Tue Jul 8, 2008 2:46 pm
Subject: Re: [PBML] Can a substitute self-reference?
learn.tech123@...
Send Email Send Email
 
Tell me, whether my solution is working or not ?

Regards,
Amit Saxena

On Tue, Jul 8, 2008 at 7:35 PM, hooyar66 <pcbcad@...> wrote:

>   --- In perl-beginner@yahoogroups.com <perl-beginner%40yahoogroups.com>,
> "hooyar66" <pcbcad@...> wrote:
> >
> > --- In perl-beginner@yahoogroups.com <perl-beginner%40yahoogroups.com>,
> "Thiago Nascimento"
> > <nascimenthiago@> wrote:
> > >
> > > Another regex is:
> > >
> > > $string =~ s/^\D*(\d.*\d)\D*$/$1/;
> > >
> > > On Tue, Jul 8, 2008 at 9:31 AM, Amit Saxena <learn.tech123@> wrote:
> > >
> > > > Hi
> > > >
> > > > Not sure whether my version is more efficient / better or not
> > (comments
> > > > awaited) :-
> > > >
> > > >
> > > > [root@111 ~]# cat v.pl
> > > > #! /usr/bin/perl
> > > >
> > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120
> > => 1, )";
> > > >
> > > > print "\nstring is [$string]";
> > > >
> > > > # $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > $string =~ s/^([^(]*\(\s+)(.*?)(,\s+\))$/\2/g;
> > > >
> > > > print "\nstring is [$string]";
> > > >
> > > > print "\nHave a nice day !\n";
> > > >
> > > > [root@111 ~]# perl v.pl
> > > >
> > > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 =>
> > 1, )]
> > > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > > Have a nice day !
> > > > [root@111 ~]#
> > > >
> > > > Regards,
> > > > Amit Saxena
> > > >
> > > > On Tue, Jul 8, 2008 at 5:46 PM, hooyar66
> > <pcbcad@<pcbcad%40hotpop.com>>
> > > > wrote:
> > > >
> > > > > --- In perl-beginner@yahoogroups.com<perl-beginner%40yahoogroups.com>
> > <perl-beginner%40yahoogroups.com><perl-beginner%
> > > > 40yahoogroups.com>,
> > > >
> > > > > "Amit Saxena"
> > > > >
> > > > > <learn.tech123@> wrote:
> > > > > >
> > > > > > It's working at my end though it does not seems to be an
> > efficient way,
> > > > > >
> > > > > > [root@111 ~]# cat v.pl
> > > > > > #! /usr/bin/perl
> > > > > >
> > > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14,
> > 120 =>
> > > > > 1, )";
> > > > > >
> > > > > > print "\nstring is [$string]";
> > > > > >
> > > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > >
> > > > > > print "\nstring is [$string]";
> > > > > >
> > > > > > print "\nHave a nice day !\n";
> > > > > >
> > > > > > [root@111 ~]# perl v.pl
> > > > > >
> > > > > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14, 120
> > => 1, )]
> > > > > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > > > > Have a nice day !
> > > > > > [root@111 ~]#
> > > > > >
> > > > > > Regards,
> > > > > > Amit Saxena
> > > > > >
> > > > > > On Tue, Jul 8, 2008 at 5:10 PM, hooyar66 <pcbcad@> wrote:
> > > > > >
> > > > > > > I want to remove from the string below - "array ( " at the
> > front and
> > > > > > > the ", )" at the end with a single substitute command.
> > > > > > >
> > > > > > > The following is what I have tried but doesn't work:
> > > > > > >
> > > > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
> > 14, 120 =>
> > > > > > > 1, )";
> > > > > > >
> > > > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > > >
> > > > > > > I can do it with a couple of line - one for each end, but
> I was
> > > > hoping
> > > > > > > it would be possible with one.
> > > > > > >
> > > > > > > Any help appreciated
> > > > > > >
> > > > > > > Thanks
> > > > > > > NJH
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > > [Non-text portions of this message have been removed]
> > > > > >
> > > > >
> > > > > Very bizarre - it's not working for me: WIN XP, Activestate v5.8.8
> > > > >
> > > > > Can you recommend a more 'efficient way'?
> > > > >
> > > > > Thanks
> > > > >
> > > > >
> > > > >
> > > >
> > > > [Non-text portions of this message have been removed]
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Thiago Nascimento
> > > perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
> > > s/(..)(.)//;print substr$_,1,1;'
> > > "...just because I don't know the meaning of my art, does not mean
> > it has no
> > > meaning..." S.D.
> > >
> > >
> > > [Non-text portions of this message have been removed]
> > >
> >
> > Thanks Thiago - I like! Seems my 'solution replication' problem is
> > elsewhere....
> >
>
> OK I've isolated my problem - I really would appreciate some help
> understanding what the problem is.
>
> My String (each character in square brackets) is really this, note the
> 'extra' whitespace:
>
> [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][
> ][8][9][ ][=][>][ ][1][3][,][ ][ ][ ][8][8][ ][=][>][ ][6][,][ ][ ][
> ][9][0][ ][=][>][ ][1][4][,][ ][ ][ ][1][2][0][ ][=][>][ ][1][,][ ][)]
>
> If I use the following command:
>
> $return =~ s/(^\D*\d.*)/$1/;
>
> I get this:
>
> [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,]
>
> Surely I ought to get the whole string as '.*' means any old junk?
>
> If I use the following command:
>
> $string =~ s/(^\D*\d.*\s*)/$1/;
>
> I get this:
>
> [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][ ]
>
> So the problem seems to be that '.*' has an issue with multiple
> whitespace... or something!
>
>
>


[Non-text portions of this message have been removed]

#26260 From: "hooyar66" <pcbcad@...>
Date: Tue Jul 8, 2008 3:20 pm
Subject: Re: Can a substitute self-reference?
hooyar66
Send Email Send Email
 
--- In perl-beginner@yahoogroups.com, "Amit Saxena"
<learn.tech123@...> wrote:
>
> Tell me, whether my solution is working or not ?
>
> Regards,
> Amit Saxena
>
> On Tue, Jul 8, 2008 at 7:35 PM, hooyar66 <pcbcad@...> wrote:
>
> >   --- In perl-beginner@yahoogroups.com
<perl-beginner%40yahoogroups.com>,
> > "hooyar66" <pcbcad@> wrote:
> > >
> > > --- In perl-beginner@yahoogroups.com
<perl-beginner%40yahoogroups.com>,
> > "Thiago Nascimento"
> > > <nascimenthiago@> wrote:
> > > >
> > > > Another regex is:
> > > >
> > > > $string =~ s/^\D*(\d.*\d)\D*$/$1/;
> > > >
> > > > On Tue, Jul 8, 2008 at 9:31 AM, Amit Saxena <learn.tech123@>
wrote:
> > > >
> > > > > Hi
> > > > >
> > > > > Not sure whether my version is more efficient / better or not
> > > (comments
> > > > > awaited) :-
> > > > >
> > > > >
> > > > > [root@111 ~]# cat v.pl
> > > > > #! /usr/bin/perl
> > > > >
> > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
14, 120
> > > => 1, )";
> > > > >
> > > > > print "\nstring is [$string]";
> > > > >
> > > > > # $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > $string =~ s/^([^(]*\(\s+)(.*?)(,\s+\))$/\2/g;
> > > > >
> > > > > print "\nstring is [$string]";
> > > > >
> > > > > print "\nHave a nice day !\n";
> > > > >
> > > > > [root@111 ~]# perl v.pl
> > > > >
> > > > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14,
120 =>
> > > 1, )]
> > > > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > > > Have a nice day !
> > > > > [root@111 ~]#
> > > > >
> > > > > Regards,
> > > > > Amit Saxena
> > > > >
> > > > > On Tue, Jul 8, 2008 at 5:46 PM, hooyar66
> > > <pcbcad@<pcbcad%40hotpop.com>>
> > > > > wrote:
> > > > >
> > > > > > --- In
perl-beginner@yahoogroups.com<perl-beginner%40yahoogroups.com>
> > > <perl-beginner%40yahoogroups.com><perl-beginner%
> > > > > 40yahoogroups.com>,
> > > > >
> > > > > > "Amit Saxena"
> > > > > >
> > > > > > <learn.tech123@> wrote:
> > > > > > >
> > > > > > > It's working at my end though it does not seems to be an
> > > efficient way,
> > > > > > >
> > > > > > > [root@111 ~]# cat v.pl
> > > > > > > #! /usr/bin/perl
> > > > > > >
> > > > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90
=> 14,
> > > 120 =>
> > > > > > 1, )";
> > > > > > >
> > > > > > > print "\nstring is [$string]";
> > > > > > >
> > > > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > > >
> > > > > > > print "\nstring is [$string]";
> > > > > > >
> > > > > > > print "\nHave a nice day !\n";
> > > > > > >
> > > > > > > [root@111 ~]# perl v.pl
> > > > > > >
> > > > > > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
14, 120
> > > => 1, )]
> > > > > > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > > > > > Have a nice day !
> > > > > > > [root@111 ~]#
> > > > > > >
> > > > > > > Regards,
> > > > > > > Amit Saxena
> > > > > > >
> > > > > > > On Tue, Jul 8, 2008 at 5:10 PM, hooyar66 <pcbcad@> wrote:
> > > > > > >
> > > > > > > > I want to remove from the string below - "array ( " at the
> > > front and
> > > > > > > > the ", )" at the end with a single substitute command.
> > > > > > > >
> > > > > > > > The following is what I have tried but doesn't work:
> > > > > > > >
> > > > > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
> > > 14, 120 =>
> > > > > > > > 1, )";
> > > > > > > >
> > > > > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > > > >
> > > > > > > > I can do it with a couple of line - one for each end, but
> > I was
> > > > > hoping
> > > > > > > > it would be possible with one.
> > > > > > > >
> > > > > > > > Any help appreciated
> > > > > > > >
> > > > > > > > Thanks
> > > > > > > > NJH
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > [Non-text portions of this message have been removed]
> > > > > > >
> > > > > >
> > > > > > Very bizarre - it's not working for me: WIN XP,
Activestate v5.8.8
> > > > > >
> > > > > > Can you recommend a more 'efficient way'?
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > > [Non-text portions of this message have been removed]
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Thiago Nascimento
> > > > perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
> > > > s/(..)(.)//;print substr$_,1,1;'
> > > > "...just because I don't know the meaning of my art, does not mean
> > > it has no
> > > > meaning..." S.D.
> > > >
> > > >
> > > > [Non-text portions of this message have been removed]
> > > >
> > >
> > > Thanks Thiago - I like! Seems my 'solution replication' problem is
> > > elsewhere....
> > >
> >
> > OK I've isolated my problem - I really would appreciate some help
> > understanding what the problem is.
> >
> > My String (each character in square brackets) is really this, note the
> > 'extra' whitespace:
> >
> > [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][
> > ][8][9][ ][=][>][ ][1][3][,][ ][ ][ ][8][8][ ][=][>][ ][6][,][ ][ ][
> > ][9][0][ ][=][>][ ][1][4][,][ ][ ][ ][1][2][0][ ][=][>][ ][1][,][ ][)]
> >
> > If I use the following command:
> >
> > $return =~ s/(^\D*\d.*)/$1/;
> >
> > I get this:
> >
> > [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,]
> >
> > Surely I ought to get the whole string as '.*' means any old junk?
> >
> > If I use the following command:
> >
> > $string =~ s/(^\D*\d.*\s*)/$1/;
> >
> > I get this:
> >
> > [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][ ]
> >
> > So the problem seems to be that '.*' has an issue with multiple
> > whitespace... or something!
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]
>


Hi Amit

Sorry - no neither your solution or Thiago's works with the text
string I referred to in my last post i.e. with each char in [].

----
[a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][
][8][9][ ][=][>][ ][1][3][,][ ][ ][ ][8][8][ ][=][>][ ][6][,][ ][ ][
][9][0][ ][=][>][ ][1][4][,][ ][ ][ ][1][2][0][ ][=][>][ ][1][,][ ][)]
----

Sorry to be a stickler but it's proper convention to 'bottom post' on
threads.

Thanks
NJH

#26261 From: "ramesh.govinda" <ramesh.govinda@...>
Date: Tue Jul 8, 2008 8:32 pm
Subject: Problem
ramesh.govinda
Send Email Send Email
 
Hello Friends,

I am learning Perl now. I have a small query.

I have a directory Z with file name Z.txt.
I would like to copy this file Z.txt to 3 new dir with new filenames
as follows
dir 1 1.txt
dir 2 2.txt
dir 3 3.txt

I would like to then open 1.txt from dir 1 and edit the first 4 lines.

For eg: I have a line as follows in the text.
x y Z
10 11 12

I need to change it as folows

x   y  z

13 14 15

I need to do the same for all the 3 files.


I have tried the following and I guess there is a much shorter way to
do this

#!/usr/bin/perl
open FILE, "z.txt" or die $!;
while (<FILE>) {
print $_;
}
mkdir("1", 0777) || print $!;
copy("z.txt","1.txt") or die "Copy failed: $!";
move("1.txt","/home/privat/temp/PerlWD/1");
mkdir("2", 0777) || print $!;
copy("z.txt","2.txt") or die "Copy failed: $!";
move("2.txt","/home/privat/temp/PerlWD/2");
mkdir("3", 0777) || print $!;
copy("z.txt","3.txt") or die "Copy failed: $!";
move("3.txt","/home/privat/temp/PerlWD/3");
print " -Done";
exit;

I am not sure how to edit the file and then save it in the respective
file name.

Looking forward to your response.

Regards,
Ramesh

#26262 From: "Amit Saxena" <learn.tech123@...>
Date: Wed Jul 9, 2008 5:04 am
Subject: Re: [PBML] Re: Can a substitute self-reference?
learn.tech123@...
Send Email Send Email
 
Surprisingly, it's working at my end.

So I think, there is some issues with configuration at your end.

Regarding the whitespace issue, always use \s+ or \s* and try to avoid the
non-greedyness of "*" by replacing it with
"*?"

Regards
Amit Saxena

On Tue, Jul 8, 2008 at 8:50 PM, hooyar66 <pcbcad@...> wrote:

>   --- In perl-beginner@yahoogroups.com <perl-beginner%40yahoogroups.com>,
> "Amit Saxena"
>
> <learn.tech123@...> wrote:
> >
> > Tell me, whether my solution is working or not ?
> >
> > Regards,
> > Amit Saxena
> >
> > On Tue, Jul 8, 2008 at 7:35 PM, hooyar66 <pcbcad@...> wrote:
> >
> > > --- In perl-beginner@yahoogroups.com <perl-beginner%40yahoogroups.com>
> <perl-beginner%40yahoogroups.com>,
> > > "hooyar66" <pcbcad@> wrote:
> > > >
> > > > --- In perl-beginner@yahoogroups.com<perl-beginner%40yahoogroups.com>
> <perl-beginner%40yahoogroups.com>,
>
> > > "Thiago Nascimento"
> > > > <nascimenthiago@> wrote:
> > > > >
> > > > > Another regex is:
> > > > >
> > > > > $string =~ s/^\D*(\d.*\d)\D*$/$1/;
> > > > >
> > > > > On Tue, Jul 8, 2008 at 9:31 AM, Amit Saxena <learn.tech123@>
> wrote:
> > > > >
> > > > > > Hi
> > > > > >
> > > > > > Not sure whether my version is more efficient / better or not
> > > > (comments
> > > > > > awaited) :-
> > > > > >
> > > > > >
> > > > > > [root@111 ~]# cat v.pl
> > > > > > #! /usr/bin/perl
> > > > > >
> > > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
> 14, 120
> > > > => 1, )";
> > > > > >
> > > > > > print "\nstring is [$string]";
> > > > > >
> > > > > > # $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > > $string =~ s/^([^(]*\(\s+)(.*?)(,\s+\))$/\2/g;
> > > > > >
> > > > > > print "\nstring is [$string]";
> > > > > >
> > > > > > print "\nHave a nice day !\n";
> > > > > >
> > > > > > [root@111 ~]# perl v.pl
> > > > > >
> > > > > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 => 14,
> 120 =>
> > > > 1, )]
> > > > > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > > > > Have a nice day !
> > > > > > [root@111 ~]#
> > > > > >
> > > > > > Regards,
> > > > > > Amit Saxena
> > > > > >
> > > > > > On Tue, Jul 8, 2008 at 5:46 PM, hooyar66
> > > > <pcbcad@<pcbcad%40hotpop.com>>
> > > > > > wrote:
> > > > > >
> > > > > > > --- In
> perl-beginner@yahoogroups.com <perl-beginner%40yahoogroups.com>
> <perl-beginner%40yahoogroups.com>
> > > > <perl-beginner%40yahoogroups.com><perl-beginner%
> > > > > > 40yahoogroups.com>,
> > > > > >
> > > > > > > "Amit Saxena"
> > > > > > >
> > > > > > > <learn.tech123@> wrote:
> > > > > > > >
> > > > > > > > It's working at my end though it does not seems to be an
> > > > efficient way,
> > > > > > > >
> > > > > > > > [root@111 ~]# cat v.pl
> > > > > > > > #! /usr/bin/perl
> > > > > > > >
> > > > > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90
> => 14,
> > > > 120 =>
> > > > > > > 1, )";
> > > > > > > >
> > > > > > > > print "\nstring is [$string]";
> > > > > > > >
> > > > > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > > > >
> > > > > > > > print "\nstring is [$string]";
> > > > > > > >
> > > > > > > > print "\nHave a nice day !\n";
> > > > > > > >
> > > > > > > > [root@111 ~]# perl v.pl
> > > > > > > >
> > > > > > > > string is [array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
> 14, 120
> > > > => 1, )]
> > > > > > > > string is [101 => 11, 89 => 13, 88 => 6, 90 => 14, 120 => 1]
> > > > > > > > Have a nice day !
> > > > > > > > [root@111 ~]#
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Amit Saxena
> > > > > > > >
> > > > > > > > On Tue, Jul 8, 2008 at 5:10 PM, hooyar66 <pcbcad@> wrote:
> > > > > > > >
> > > > > > > > > I want to remove from the string below - "array ( " at the
> > > > front and
> > > > > > > > > the ", )" at the end with a single substitute command.
> > > > > > > > >
> > > > > > > > > The following is what I have tried but doesn't work:
> > > > > > > > >
> > > > > > > > > my $string = "array ( 101 => 11, 89 => 13, 88 => 6, 90 =>
> > > > 14, 120 =>
> > > > > > > > > 1, )";
> > > > > > > > >
> > > > > > > > > $string =~ s/array\s\(\s(.*),\s\)/$1/;
> > > > > > > > >
> > > > > > > > > I can do it with a couple of line - one for each end, but
> > > I was
> > > > > > hoping
> > > > > > > > > it would be possible with one.
> > > > > > > > >
> > > > > > > > > Any help appreciated
> > > > > > > > >
> > > > > > > > > Thanks
> > > > > > > > > NJH
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > [Non-text portions of this message have been removed]
> > > > > > > >
> > > > > > >
> > > > > > > Very bizarre - it's not working for me: WIN XP,
> Activestate v5.8.8
> > > > > > >
> > > > > > > Can you recommend a more 'efficient way'?
> > > > > > >
> > > > > > > Thanks
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > > [Non-text portions of this message have been removed]
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Thiago Nascimento
> > > > > perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
> > > > > s/(..)(.)//;print substr$_,1,1;'
> > > > > "...just because I don't know the meaning of my art, does not mean
> > > > it has no
> > > > > meaning..." S.D.
> > > > >
> > > > >
> > > > > [Non-text portions of this message have been removed]
> > > > >
> > > >
> > > > Thanks Thiago - I like! Seems my 'solution replication' problem is
> > > > elsewhere....
> > > >
> > >
> > > OK I've isolated my problem - I really would appreciate some help
> > > understanding what the problem is.
> > >
> > > My String (each character in square brackets) is really this, note the
> > > 'extra' whitespace:
> > >
> > > [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][
> > > ][8][9][ ][=][>][ ][1][3][,][ ][ ][ ][8][8][ ][=][>][ ][6][,][ ][ ][
> > > ][9][0][ ][=][>][ ][1][4][,][ ][ ][ ][1][2][0][ ][=][>][ ][1][,][ ][)]
> > >
> > > If I use the following command:
> > >
> > > $return =~ s/(^\D*\d.*)/$1/;
> > >
> > > I get this:
> > >
> > > [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,]
> > >
> > > Surely I ought to get the whole string as '.*' means any old junk?
> > >
> > > If I use the following command:
> > >
> > > $string =~ s/(^\D*\d.*\s*)/$1/;
> > >
> > > I get this:
> > >
> > > [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][ ]
> > >
> > > So the problem seems to be that '.*' has an issue with multiple
> > > whitespace... or something!
> > >
> > >
> > >
> >
> >
> > [Non-text portions of this message have been removed]
> >
>
> Hi Amit
>
> Sorry - no neither your solution or Thiago's works with the text
> string I referred to in my last post i.e. with each char in [].
>
> ----
> [a][r][r][a][y][ ][(][ ][ ][ ][1][0][1][ ][=][>][ ][1][1][,][ ][ ][
> ][8][9][ ][=][>][ ][1][3][,][ ][ ][ ][8][8][ ][=][>][ ][6][,][ ][ ][
> ][9][0][ ][=][>][ ][1][4][,][ ][ ][ ][1][2][0][ ][=][>][ ][1][,][ ][)]
> ----
>
> Sorry to be a stickler but it's proper convention to 'bottom post' on
> threads.
>
> Thanks
> NJH
>
>
>


[Non-text portions of this message have been removed]

#26263 From: merlyn@...
Date: Wed Jul 9, 2008 2:38 pm
Subject: Re: [PBML] Re: Can a substitute self-reference?
merlynstoneh...
Send Email Send Email
 
>>>>> "Amit" == Amit Saxena <learn.tech123@...> writes:

Amit> Regarding the whitespace issue, always use \s+ or \s* and try to avoid the
Amit> non-greedyness of "*" by replacing it with
Amit> "*?"

You mean avoid the greediness?  By default, * is greedy.  *? is "lazy".

And I don't agree "in general".  It's important to keep it in mind, but
it's not "automatically better".

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26264 From: "Amit Saxena" <learn.tech123@...>
Date: Wed Jul 9, 2008 2:50 pm
Subject: Re: [PBML] Re: Can a substitute self-reference?
learn.tech123@...
Send Email Send Email
 
Sorry about that typo,

What I meant was :-

Regarding the whitespace issue, always use \s+ or \s* and try to avoid the
greedyness of "*" by replacing it with "*?"


Regards,
Amit Saxena

On Wed, Jul 9, 2008 at 8:08 PM, <merlyn@...> wrote:

>   >>>>> "Amit" == Amit Saxena
<learn.tech123@...<learn.tech123%40gmail.com>>
> writes:
>
> Amit> Regarding the whitespace issue, always use \s+ or \s* and try to
> avoid the
> Amit> non-greedyness of "*" by replacing it with
> Amit> "*?"
>
> You mean avoid the greediness? By default, * is greedy. *? is "lazy".
>
> And I don't agree "in general". It's important to keep it in mind, but
> it's not "automatically better".
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@... <merlyn%40stonehenge.com>> <URL:
> http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside
> discussion
>
>


[Non-text portions of this message have been removed]

#26265 From: "Jenda Krynicky" <Jenda@...>
Date: Wed Jul 9, 2008 3:59 pm
Subject: Re: [PBML] Re: Can a substitute self-reference?
jendaperl
Send Email Send Email
 
From: "Amit Saxena" <learn.tech123@...>
> Sorry about that typo,
>
> What I meant was :-
>
> Regarding the whitespace issue, always use \s+ or \s* and try to avoid the
> greedyness of "*" by replacing it with "*?"
>
> Regards,
> Amit Saxena

!post top- not Do

what good is
  $str =~ s/^\s*?//;
?

Do not "try to avoid greedines"! Understand the difference and choose
the right (greedy vs. lazy) version accordingly.

Jenda
===== Jenda@... === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
	 -- Terry Pratchett in Sourcery

#26267 From: "welches3993" <welches3993@...>
Date: Wed Jul 9, 2008 11:13 pm
Subject: Jr-Mid Level PERL Developer in Colorado
welches3993
Send Email Send Email
 
Please respond if you would be interested in a 6 month contract to
hire opportunity in the Northern Suburbs of Colorado. Will consider a
Jr Level Perl Developer with recent experience of the following
skills.

Mid-level Software Developer:
PERL (2+ years with recent experience)
SQL (2+ years with recent experience)
UNIX (2+ years with recent experience)
PHP (nice to have, not required)
C++ (nice to have, not required)
Berkeley DB (nice to have, not required)
Minimum three years professional software development experience
(recent)
Recent history of working on development teams with at least 2 other
people (i.e. no solos…), and genuinely enjoys working on teams (i.e.
not lip service)
Recent history of working on production systems (i.e. software that
is currently used by hundreds, thousands, or more customers)
Recent history of interacting with a Product Management, Quality
Assurance, and Operations group
This is not a work from home position.

Thanks,
Sarah Welch

#26268 From: Louis-Philippe <l0u1sph1l1ppe@...>
Date: Thu Jul 10, 2008 5:01 pm
Subject: Re: [PBML] Problem
l0u1sph1l1ppe@...
Send Email Send Email
 
Hi Ramesh,

I don't know if its shorter, but here's an other way to do it:
_______________________________________________

#!/usr/bin/perl -w

use strict;
use IO::File;

my $dir = '/YOUR_TOP_DIR';

my $z = new IO::File "< $dir/z/z.txt" or warn "can't open z.txt: $!\n";

foreach my $num (1..3) {
     mkdir("$dir/$num", 0777) or warn "cant't create dir $num: $!\n";
     my $new = new IO::File "> $dir/$num/$num.txt" or warn "can't open $num.txt:
$!\n";
     while (<$z>) {
         s/10 11 12/13 14 15/;
         print $new $_;
     }
     $new->close;
}

$z->close;
____________________________________________________

I use the IO::File library as I find its more elegant to play with file handles,
and instead of copying + moving the files
I just slurp it, mangle it, spit it straight up in the new file inside of a
foreach loop.
the string replacement could of course be enhanced to your taste...

L-P



----ramesh.govinda@... wrote ----

                 Hello Friends,

I am learning Perl now. I have a small query.

I have a directory Z with file name Z.txt.
I would like to copy this file Z.txt to 3 new dir with new filenames
as follows
dir 1 1.txt
dir 2 2.txt
dir 3 3.txt

I would like to then open 1.txt from dir 1 and edit the first 4 lines.

For eg: I have a line as follows in the text.
x y Z
10 11 12

I need to change it as folows

x   y  z

13 14 15

I need to do the same for all the 3 files.

I have tried the following and I guess there is a much shorter way to
do this

#!/usr/bin/perl
open FILE, "z.txt" or die $!;
while (<FILE>) {
print $_;
}
mkdir("1", 0777) || print $!;
copy("z.txt","1.txt") or die "Copy failed: $!";
move("1.txt","/home/privat/temp/PerlWD/1");
mkdir("2", 0777) || print $!;
copy("z.txt","2.txt") or die "Copy failed: $!";
move("2.txt","/home/privat/temp/PerlWD/2");
mkdir("3", 0777) || print $!;
copy("z.txt","3.txt") or die "Copy failed: $!";
move("3.txt","/home/privat/temp/PerlWD/3");
print " -Done";
exit;

I am not sure how to edit the file and then save it in the respective
file name.

Looking forward to your response.

Regards,
Ramesh




[Non-text portions of this message have been removed]

#26269 From: "Jenda Krynicky" <Jenda@...>
Date: Thu Jul 10, 2008 7:30 pm
Subject: Re: [PBML] Problem
jendaperl
Send Email Send Email
 
From: Louis-Philippe <l0u1sph1l1ppe@...>
> I don't know if its shorter, but here's an other way to do it:
> _______________________________________________
>
> #!/usr/bin/perl -w
>
> use strict;
> use IO::File;
>
> my $dir = '/YOUR_TOP_DIR';
>
> my $z = new IO::File "< $dir/z/z.txt" or warn "can't open z.txt: $!\n";
>
> foreach my $num (1..3) {
>     mkdir("$dir/$num", 0777) or warn "cant't create dir $num: $!\n";
>     my $new = new IO::File "> $dir/$num/$num.txt" or warn "can't open
$num.txt: $!\n";
>     while (<$z>) {
>         s/10 11 12/13 14 15/;
>         print $new $_;
>     }
>     $new->close;
> }
>
> $z->close;
> ____________________________________________________
>
> I use the IO::File library as I find its more elegant to play with file
handles,

It's no longer necessary. You can use a (lexical) variable wherever
you need a filehandle. Without loading any modules. As long as you
use a resonably recent Perl. (5.8, maybe even 5.6 would be enough).

open my $z, '<', $dir/z/z.txt" or die "can't open z.txt: $!\n";
...
close $z;

and you can pass the $z around or store it in data structures the
same way as with IO::File.

Plus in both cases if you declare the variable in the right scope you
do not need to explicitely close it. The file will be closed as the
variable falls out of scope.

Jenda
===== Jenda@... === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
	 -- Terry Pratchett in Sourcery

#26270 From: Louis-Philippe <l0u1sph1l1ppe@...>
Date: Thu Jul 10, 2008 7:59 pm
Subject: Re: [PBML] Problem
l0u1sph1l1ppe@...
Send Email Send Email
 
I had read that somewhere about the filehandle in a lexical variable...
but I am usually conservative about changing ways when something works!
so thanks Jenda!  I went a bit further today ;).

so, Ramesh, here is how it looks with Jenda's simplification:

_____________________________________________________________

#!/usr/bin/perl -w

use strict;

my $dir = '/YOUR_TOP_DIR';

open my $z, '<', "$dir/z/z.txt" or die "can't open z.txt: $!\n";

foreach my $num (1..3) {
     mkdir("$dir/$num", 0777) or warn "cant't create dir $num: $!\n";
     open my $new, '>', "$dir/$num/$num.txt" or warn "can't open $num.txt: $!\n";
     while (<$z>) {
         s/10 11 12/13 14 15/;
         print $new $_;
     }
}

_______________________________________________________


that would do it!

L-P

[Non-text portions of this message have been removed]

#26271 From: "shanniknite" <shanniknite@...>
Date: Fri Jul 11, 2008 2:33 am
Subject: writing perl script
shanniknite
Send Email Send Email
 
I have no clue of how to write cgi scripts.  Can someone tell me and
explain to me how to write the following Alaska was the 49th state to
sign the constitution, arizona was the 48th state, and alabama was
the 22nd state for homer.html: <!homer.html>
<HTML>
<HEAD><TITLE>Jackson Elementary School</TITLE><BASEFONT SIZE=5></HEAD>
<BODY>
<IMG SRC="jackson.gif"><BR><BR>
Click a state name<BR>
<A HREF="http://www.?.netfirms.com/cgi-bin/ch2/c02ex3.cgi?
state=Alabama&cap=Montgomery">Alabama</A><BR>
<A HREF="http://www.?.netfirms.com/cgi-bin/ch2/c02ex3.cgi?
state=Alaska&cap=Juneau">Alaska</A><BR>
<A HREF="http://www.?.netfirms.com/cgi-bin/ch2/c02ex3.cgi?
state=Arizona&cap=Phoenix">Arizona</A><BR>
<A HREF="http://www.?.netfirms.com/cgi-bin/ch2/c02ex3.cgi?
state=Arkansas&cap=Little+Rock">Arkansas</A><BR>
</BODY>
</HTML>
and then homer.cgi script to be modified but do not know where to
begin.
homer.cgi script:
#!/usr/bin/perl
#homer.cgi - creates a dynamic Web page
print "Content-type: text/html\n\n";

use CGI qw(:standard);

#create Web page
print "<HTML>\n";
print "<HEAD><TITLE>Jackson Elementary School</TITLE><BASEFONT
SIZE=5></HEAD>\n";
print "<BODY>\n";
print "The capital of ", param('state')," is ", param('cap'), ".\n";
print "</BODY>\n";
print "</HTML>\n";

#26273 From: "sruthi6656" <sruthi6656@...>
Date: Mon Jul 14, 2008 12:30 pm
Subject: Learn new techniques & concepts. Stanford Computer Security Program
sruthi6656
Send Email Send Email
 
Learn new techniques & concepts. Stanford Computer Security Program

http://computernetwork-maya.blogspot.com


work @ home online
http://sai-earnmoneyonline.blogspot.com


Top 25 Camera phones
Features, Reviews & Prices Register for Articles on Gadgets!
Virgin Mobile Phones
The Coolest Phones From Virgin Mobile India. Check Here Now!

http://mobilesaccessories-sai.blogspot.com

#26274 From: "ramesh.govinda" <ramesh.govinda@...>
Date: Tue Jul 15, 2008 5:39 am
Subject: Re: [PBML] Problem
ramesh.govinda
Send Email Send Email
 
Hi LP ,

Thanks for your advice.

I have a small problem with my code.


I have a text file z.txt with following lines

*transformation
X Y Z
10 20 30

Finally i need to have a the same text file as follows,

*transformation
X Y Z
50 60 80


But instead when I run the code, It again types the *transformation
line without replacing the last line. The output i ghet from the code
is as follows,

*transformation
X Y Z
10  20  30


*transformation

My code is as follows,

#!\usr\bin\perl
use warnings;
use strict;
open (IN,'+<','z.txt');
my @file = <IN>;
my $count = 0;
foreach my $file (@file){
if ($file =~ /\*transformation/){
$count = $count + 1;
}
if ( $count == 1 ){
$count = $count + 1;
}
if ( $count == 2 ){
$file =~ s/10  20  30/50  60  80/g;
print IN $file;
$count = 0;
last;
}
}
close IN;

Could you please help me on this code.

Regards,
Ramesh


--- In perl-beginner@yahoogroups.com, Louis-Philippe
<l0u1sph1l1ppe@...> wrote:
>
> I had read that somewhere about the filehandle in a lexical variable...
> but I am usually conservative about changing ways when something works!
> so thanks Jenda!  I went a bit further today ;).
>
> so, Ramesh, here is how it looks with Jenda's simplification:
>
> _____________________________________________________________
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $dir = '/YOUR_TOP_DIR';
>
> open my $z, '<', "$dir/z/z.txt" or die "can't open z.txt: $!\n";
>
> foreach my $num (1..3) {
>     mkdir("$dir/$num", 0777) or warn "cant't create dir $num: $!\n";
>     open my $new, '>', "$dir/$num/$num.txt" or warn "can't open
$num.txt: $!\n";
>     while (<$z>) {
>         s/10 11 12/13 14 15/;
>         print $new $_;
>     }
> }
>
> _______________________________________________________
>
>
> that would do it!
>
> L-P
>
> [Non-text portions of this message have been removed]
>

#26275 From: "Jeff Shu" <santa98bn@...>
Date: Tue Jul 15, 2008 2:08 pm
Subject: check even number using subroutine
santa98bn
Send Email Send Email
 
Hi everyone:

   I wrote a function to check even number. inside the subroutine I
return '1' if the number is even, otherwise return '0'.

   a) I did some search, Perl doesn't have a boolean variable like
'true' or false. so return '1' is like return true, all other numbers
is like 'false'

   My code doesn't detect the even number correctly. Please review my
code and tell me what I did wrong. I appreciate your help!

   #!/usr/bin/perl

  sub is_even()
{
   print "@_\n"; #debugging statement

   if((@_ % 2) == 0)
   {
     return 1;
   }
   else
   {
     return 0;
   }
}

for($i = 1; $i <= 10; $i++)
{
   if(&is_even($i))
   {
     print "$i is a even number.\n";

   }

   else
   {
     print "$i is not an even number.\n";
   }
}

#26276 From: "Peter L. Berghold" <peter@...>
Date: Tue Jul 15, 2008 2:19 pm
Subject: Re: [PBML] check even number using subroutine
blue_cowdawg
Send Email Send Email
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeff Shu wrote:

>   a) I did some search, Perl doesn't have a boolean variable like
> 'true' or false. so return '1' is like return true, all other numbers
> is like 'false'
>

any non-zero value is considered a true.


>   if((@_ % 2) == 0)


That will not evaluate the value inside the array @_ but the number of
elements in it.  You are referencing the array in a scalar context.

What you probably want is

	 my $val = shift;
         return ( ($val % 2 ) == 0 );




There's actually more than one way to skin this cat....


- --

Peter L. Berghold     http://www.berghold.net   peter@...
Unix Professional     Dog Agility Fan   Crazed Cook
"Those who fail to learn from history are condemned to repeat it."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIfLIHUM9/01RIhaARAiH2AKCRRDpHVmigmYAt2mNHQrWkuNgG9gCgtvwU
qIN8M/WFdISLCamNxEhcPyg=
=zp5f
-----END PGP SIGNATURE-----

#26277 From: jiqiang yao <jiqiang123@...>
Date: Tue Jul 15, 2008 2:47 pm
Subject: use of unitialized value
jiqiang123@...
Send Email Send Email
 
Hi, everybody:

I am reading all the data from a table, the following is my code.

I got a warning message of "use of uninitialized value at the line marked with
'#########'.

I checked the data and found no data is lost. What is the reason that this
message is generated? anybody knows?

-------------- my code -----------------------------------
    my $sql      =  "select * from table1";
    my $cursor  =  $dbh->prepare($sql);
       $cursor  -> execute();


    while( my ($ID,$NUMBER) = $cursor->fetchrow_array)
       {
            if($ID)   ################
            {print "$SNP_ID\t$NUMBER\n";}
        }
       $cursor  -> finish();

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

#26278 From: "Jenda Krynicky" <Jenda@...>
Date: Tue Jul 15, 2008 2:55 pm
Subject: Re: [PBML] check even number using subroutine
jendaperl
Send Email Send Email
 
From: "Jeff Shu" <santa98bn@...>
> Hi everyone:
>
>   I wrote a function to check even number. inside the subroutine I
> return '1' if the number is even, otherwise return '0'.
>
>   a) I did some search, Perl doesn't have a boolean variable like
> 'true' or false. so return '1' is like return true, all other numbers
> is like 'false'
>
>   My code doesn't detect the even number correctly. Please review my
> code and tell me what I did wrong. I appreciate your help!
>
>   #!/usr/bin/perl
>
>  sub is_even()
> {
>   print "@_\n"; #debugging statement
>
>   if((@_ % 2) == 0)

@_ or @array evaluates to the length of the array in scalar context.
Try

sub foo {
  my $x = @_;
  print "foo($x)\n";
}
foo(99);
foo(1,2,4,6);


You need to use $_[0] if you want to access the first parameter of
the subroutine.

Jenda
===== Jenda@... === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
	 -- Terry Pratchett in Sourcery

#26279 From: "Jenda Krynicky" <Jenda@...>
Date: Tue Jul 15, 2008 2:55 pm
Subject: Re: [PBML] check even number using subroutine
jendaperl
Send Email Send Email
 
From: "Peter L. Berghold" <peter@...>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Jeff Shu wrote:
>
> >   a) I did some search, Perl doesn't have a boolean variable like
> > 'true' or false. so return '1' is like return true, all other numbers
> > is like 'false'
> >
>
> any non-zero value is considered a true.

That's not exactly true. '0E0' or even '0 but true' both evaluate to
zero in numerical context, even without generating any warnings, but
they are still not false.

According to the docs (perldata):

=======================
A scalar value is interpreted as TRUE in the Boolean sense if it is
not the null string or the number 0 (or its string equivalent, "0").
The Boolean context is just a special kind of scalar context where no
conversion to a string or a number is ever performed.

There are actually two varieties of null strings (sometimes referred
to as "empty" strings), a defined one and an undefined one. The
defined version is just a string of length zero, such as "". The
undefined version is the value that indicates that there is no real
value for something, such as when there was an error, or at end of
file, or when you refer to an uninitialized variable or element of an
array or hash.
=======================


That is an undef, "", 0, 0.0 and "0" is false, everything else is
true.

Jenda
===== Jenda@... === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
	 -- Terry Pratchett in Sourcery

#26280 From: "Jenda Krynicky" <Jenda@...>
Date: Tue Jul 15, 2008 2:57 pm
Subject: Re: [PBML] use of unitialized value
jendaperl
Send Email Send Email
 
From:            jiqiang yao <jiqiang123@...>
> I am reading all the data from a table, the following is my code.
>
> I got a warning message of "use of uninitialized value at the line marked with
'#########'.
>
> I checked the data and found no data is lost. What is the reason that this
message is generated? anybody knows?
>
> -------------- my code -----------------------------------
>    my $sql      =  "select * from table1";
>    my $cursor  =  $dbh->prepare($sql);
>       $cursor  -> execute();
>
>
>    while( my ($ID,$NUMBER) = $cursor->fetchrow_array)
>       {
>            if($ID)   ################
>            {print "$SNP_ID\t$NUMBER\n";}
>        }
>       $cursor  -> finish();
>
> ----------------------------------------------------

I bet it's actually the next line. Where do you assign to the $SNP_ID
variable? Where did you actually declare that variable? Your script
doesn't miss the "use strict" line, does it?

Jenda
===== Jenda@... === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
	 -- Terry Pratchett in Sourcery

#26281 From: jiqiang yao <jiqiang123@...>
Date: Tue Jul 15, 2008 3:12 pm
Subject: Re: [PBML] use of unitialized value
jiqiang123@...
Send Email Send Email
 
Sorry, next line $SNP_ID is a typo, it should be $ID

--- On Tue, 7/15/08, Jenda Krynicky <Jenda@...> wrote:
From: Jenda Krynicky <Jenda@...>
Subject: Re: [PBML] use of unitialized value
To: perl-beginner@yahoogroups.com
Date: Tuesday, July 15, 2008, 10:57 AM











             From:            jiqiang yao <jiqiang123@yahoo. com>

> I am reading all the data from a table, the following is my code.

>

> I got a warning message of "use of uninitialized value at the line marked with
'#########'.

>

> I checked the data and found no data is lost. What is the reason that this
message is generated? anybody knows?

>

> ------------ -- my code ------------ --------- --------- -----

>    my $sql      =  "select * from table1";

>    my $cursor  =  $dbh->prepare( $sql);

>       $cursor  -> execute();

>

>

>    while( my ($ID,$NUMBER) = $cursor->fetchrow_ array)

>       {

>            if($ID)   ############ ####

>            {print "$SNP_ID\t$NUMBER\ n";}

>        }

>       $cursor  -> finish();

>

> ------------ --------- --------- --------- --------- ----



I bet it's actually the next line. Where do you assign to the $SNP_ID

variable? Where did you actually declare that variable? Your script

doesn't miss the "use strict" line, does it?



Jenda

===== Jenda@Krynicky. cz === http://Jenda. Krynicky. cz =====

When it comes to wine, women and song, wizards are allowed

to get drunk and croon as much as they like.

	 -- Terry Pratchett in Sourcery





























[Non-text portions of this message have been removed]

#26282 From: "Dukelow, Don" <dukelow@...>
Date: Tue Jul 15, 2008 3:43 pm
Subject: Reading a binary file
dondukelow
Send Email Send Email
 
I'm tring to read a binary file using code out of the Perl Cook Book.

#! /usr/bin/perl

use warnings;
use strict;
use IO::Seekable;
use open IO => ":raw";
my ($file, @addrs) = @ARGV;
open(FH, $file);
$/ = "\000";
foreach my $addr (@addrs) {
    $addr = oct $addr if $addr =~ /^0/;
    seek (FH, $addr, SEEK_SET) or die "can't seek tpo $addr in $file: $!";
    printf qq(%#x %#o %d "%#s"\n), $addr, $addr, $addr, scalar <>;
}

This is the output I get.

0 0 0 "# ACME Report Log, 28 February, 2008 (15:41), "CCLM" on "vmcdlb10" FLEXlm
v9.2
Z5 2 3
C;;mmnO[d6=hV
oOO44b3P<Umo
pHH^^LZgyRK
y==DD'F.]ayth$my3P#0XyvW{$
rTT44wp~f7\H6fKrAv7_.rxNGf
i||nn,[')cR*b
g++mm&zTN@6vmiG)"L(9=)B,>i
h//4489\'iXK=
tRR.tV+u=PP^hW5-yyDK~W55U\<yvmmL{,r$mN1l^55$<<Adc-+r( hea.c]/g;})ZH]8::<
         ;"cw' #WMkv1:LL6?[-)$ %yw\;wnAv^H*M:WWG,MKa{!%gnGEdW_8~II@
         T5H8-)'+GlXg_]dsII=/}-:g*eE3N=#?>,YYrz0C5@gkj}}#{W@@$d7@@i/Y##C
         XUO44vRx66cPlcc~r6==|{Z::$xv]]O[U>>y50//fa/jjvmnqqm"488Rx4vvH
         [&-<<SA"ZZ:m`33BA-HHv]peeShPll[5*..4vPOO6|T44MdB~~*y&IIlcn66-
          y8~~1eF(G

It reads the first line OK, and I'm guessing something changes after that.  So
all I get is garbage.

Can anyone point me in poroper direction to figure this out?
-----
Don Dukelow
HP License Team
Hewlett-Packard Company
Tel: 810-728-3388
e-mail: dukelow@...

#26283 From: merlyn@...
Date: Tue Jul 15, 2008 4:49 pm
Subject: Re: [PBML] Reading a binary file
merlynstoneh...
Send Email Send Email
 
>>>>> "Dukelow," == Dukelow, Don <dukelow@...> writes:

Dukelow,> It reads the first line OK, and I'm guessing something changes after
that.  So all I get is garbage.

"binary" usually looks like garbage.  What do you expect to see when
you look in this file, and why do you think "binary" mode will help?

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#26284 From: Louis-Philippe <l0u1sph1l1ppe@...>
Date: Tue Jul 15, 2008 5:30 pm
Subject: Re: [PBML] Problem
l0u1sph1l1ppe@...
Send Email Send Email
 
Hi Ramesh,

I do not get your idea totally...
Do you want to get the block of 3 lines 2 times in the result?
also, I don't understand what you try to achieve with your conditionals...

If I try guessing my best, what I understand is that you want to append the same
3 lines from the begining of the file to the end of the file but with the 10 20
30 replaced by 50 60 80.  If that is the case I think you could do it without
the conditional blocks, something like this:

#!\usr\bin\perl
use warnings;
use strict;
open (IN,'+<','z.txt');
my @file = <IN>;
foreach my $file (@file){
$file =~ s/10  20  30/50  60  80/;
print IN $file;
}
close IN;


----ramesh.govinda@... wrote ----

                 Hi LP ,

Thanks for your advice.

I have a small problem with my code.

I have a text file z.txt with following lines

*transformation
X Y Z
10 20 30

Finally i need to have a the same text file as follows,

*transformation
X Y Z
50 60 80

But instead when I run the code, It again types the *transformation
line without replacing the last line. The output i ghet from the code
is as follows,

*transformation
X Y Z
10  20  30

*transformation

My code is as follows,

#!\usr\bin\perl
use warnings;
use strict;
open (IN,'+<','z.txt');
my @file = <IN>;
my $count = 0;
foreach my $file (@file){
if ($file =~ /\*transformation/){
$count = $count + 1;
}
if ( $count == 1 ){
$count = $count + 1;
}
if ( $count == 2 ){
$file =~ s/10  20  30/50  60  80/g;
print IN $file;
$count = 0;
last;
}
}
close IN;

Could you please help me on this code.

Regards,
Ramesh

--- In perl-beginner@yahoogroups.com, Louis-Philippe
<l0u1sph1l1ppe@...> wrote:
>
> I had read that somewhere about the filehandle in a lexical variable...
> but I am usually conservative about changing ways when something works!
> so thanks Jenda!  I went a bit further today ;).
>
> so, Ramesh, here is how it looks with Jenda's simplification:
>
> __________________________________________________________
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $dir = '/YOUR_TOP_DIR';
>
> open my $z, '<', "$dir/z/z.txt" or die "can't open z.txt: $!\n";
>
> foreach my $num (1..3) {
>     mkdir("$dir/$num", 0777) or warn "cant't create dir $num: $!\n";
>     open my $new, '>', "$dir/$num/$num.txt" or warn "can't open
$num.txt: $!\n";
>     while (<$z>) {
>         s/10 11 12/13 14 15/;
>         print $new $_;
>     }
> }
>
> _______________________________________________________
>
>
> that would do it!
>
> L-P
>
> [Non-text portions of this message have been removed]
>




[Non-text portions of this message have been removed]

#26285 From: Sylvain Pascal <sylvainpascal@...>
Date: Wed Jul 16, 2008 9:43 am
Subject: Re : [PBML] Problem
sylvainpascal
Send Email Send Email
 
Hi all,
well, I suppose, another response can be:

#!\usr\bin\perl
use warnings;
use strict;
open (IN,'+<','z. txt');
my @file = <IN>;
map {$_=~ s(10 20 30)(50 60 80); print IN, $_;} @file;

close IN;

  ----
Sylvain PASCAL LACOMBE
sylvainpascal@...



----- Message d'origine ----
De : Louis-Philippe <l0u1sph1l1ppe@...>
À : perl-beginner@yahoogroups.com
Envoyé le : Mardi, 15 Juillet 2008, 19h30mn 12s
Objet : Re: [PBML] Problem


Hi Ramesh,

I do not get your idea totally...
Do you want to get the block of 3 lines 2 times in the result?
also, I don't understand what you try to achieve with your conditionals. ..

If I try guessing my best, what I understand is that you want to append the same
3 lines from the begining of the file to the end of the file but with the 10 20
30 replaced by 50 60 80.  If that is the case I think you could do it without
the conditional blocks, something like this:

#!\usr\bin\perl
use warnings;
use strict;
open (IN,'+<','z. txt');
my @file = <IN>;
foreach my $file (@file){
$file =~ s/10  20  30/50  60  80/;
print IN $file;
}
close IN;

----ramesh.govinda@ yahoo.com wrote ----

Hi LP ,

Thanks for your advice.

I have a small problem with my code.

I have a text file z.txt with following lines

*transformation
X Y Z
10 20 30

Finally i need to have a the same text file as follows,

*transformation
X Y Z
50 60 80

But instead when I run the code, It again types the *transformation
line without replacing the last line. The output i ghet from the code
is as follows,

*transformation
X Y Z
10  20  30

*transformation

My code is as follows,

#!\usr\bin\perl
use warnings;
use strict;
open (IN,'+<','z. txt');
my @file = <IN>;
my $count = 0;
foreach my $file (@file){
if ($file =~ /\*transformation/ ){
$count = $count + 1;
}
if ( $count == 1 ){
$count = $count + 1;
}
if ( $count == 2 ){
$file =~ s/10  20  30/50  60  80/g;
print IN $file;
$count = 0;
last;
}
}
close IN;

Could you please help me on this code.

Regards,
Ramesh

--- In perl-beginner@ yahoogroups. com, Louis-Philippe
<l0u1sph1l1ppe@ ...> wrote:
>
> I had read that somewhere about the filehandle in a lexical variable...
> but I am usually conservative about changing ways when something works!
> so thanks Jenda!  I went a bit further today ;).
>
> so, Ramesh, here is how it looks with Jenda's simplification:
>
> ____________ _________ _________ _________ _________ _________ _
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $dir = '/YOUR_TOP_DIR' ;
>
> open my $z, '<', "$dir/z/z.txt" or die "can't open z.txt: $!\n";
>
> foreach my $num (1..3) {
>     mkdir("$dir/ $num", 0777) or warn "cant't create dir $num: $!\n";
>     open my $new, '>', "$dir/$num/$ num.txt" or warn "can't open
$num.txt: $!\n";
>     while (<$z>) {
>         s/10 11 12/13 14 15/;
>         print $new $_;
>     }
> }
>
> ____________ _________ _________ _________ _________ _______
>
>
> that would do it!
>
> L-P
>
> [Non-text portions of this message have been removed]
>



[Non-text portions of this message have been removed]




      
_____________________________________________________________________________
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

[Non-text portions of this message have been removed]

#26286 From: merlyn@...
Date: Wed Jul 16, 2008 3:54 pm
Subject: Re: Re : [PBML] Problem
merlynstoneh...
Send Email Send Email
 
>>>>> "Sylvain" == Sylvain Pascal <sylvainpascal@...> writes:

Sylvain> map {$_=~ s(10 20 30)(50 60 80); print IN, $_;} @file;

Please don't use map in a void context.  Please don't alter $_
within the map.

If you're offering help, you're now the blind leading the blind.
Please learn more about Perl before giving help.  Sit back a bit.
Learn more.

Others will provide solutions.  Your solution is more harm than good.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Messages 26255 - 26286 of 27459   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help