[29912] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1155 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 3 03:50:22 2008

Date: Thu, 3 Jan 2008 00:50:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 3 Jan 2008     Volume: 11 Number: 1155

Today's topics:
        Regular Expression for XML Parsing tushar.saxena@gmail.com
    Re: Regular Expression for XML Parsing <jurgenex@hotmail.com>
    Re: Regular Expression for XML Parsing patriknym@hotmail.com
    Re: Regular Expression for XML Parsing <tadmc@seesig.invalid>
    Re: Regular Expression for XML Parsing <bik.mido@tiscalinet.it>
    Re: reopen the file <ben@morrow.me.uk>
    Re: reopen the file <joost@zeekat.nl>
    Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6 <simon.chao@fmr.com>
    Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6 <simon.chao@fmr.com>
        s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I <tzz@lifelogs.com>
    Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6 <bik.mido@tiscalinet.it>
    Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6 <abigail@abigail.be>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <tzz@lifelogs.com>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <tzz@lifelogs.com>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <simon.chao@fmr.com>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <abigail@abigail.be>
    Re: s/A/B/ and s/B/C/ but don't want A -> C <rvtol+news@isolution.nl>
        Specifying options for Net::SFTP <newsuser@dicksonlife.com>
    Re: Specifying options for Net::SFTP <rkb@i.frys.com>
    Re: Specifying options for Net::SFTP <newsuser@dicksonlife.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 27 Dec 2007 12:59:12 -0800 (PST)
From: tushar.saxena@gmail.com
Subject: Regular Expression for XML Parsing
Message-Id: <aece3d31-ff36-421f-ab96-15b1c1c7a91c@d21g2000prf.googlegroups.com>

Hi,

I have a set of XML files from which I need to extract some data. The
format of the file is as follows :

<tag1>
   <tag3>DATA1</tag3>
</tag1>

<tag2>
   <tag3>DATA2</tag3>
</tag2>

I need to extract the DATA part of the xml structure

Note : tag3 can be contained either within tag1 or tag2, but I need to
extract data only from tag1. i.e. DATA1 should be extracted, but not
DATA2

If I want to get both DATA1 and DATA2 I can use a simple regex like :

if (($_ =~ /<tag3>(\w+)<\/tag3>/g))
{
    print $1
}

But if I try to get only DATA1 (embedded within tag1) I try using
something like this, but am unable to get it to work

if (($_ =~ /<tag1>[\n\s\S\w\W]*<tag2>(\w+)<\/tag2>[\n\s\S\w\W]*<\/
tag1>/g))
{
    print $1
}

In this second case, the match itself fails.

Any help would be appreciated !


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

Date: Thu, 27 Dec 2007 22:49:34 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Regular Expression for XML Parsing
Message-Id: <isa8n3df48n8vq1fdpf9eqnditu8gaonjv@4ax.com>

On tushar.saxena@gmail.com wrote:
>I have a set of XML files 
>I need to extract the DATA part of the xml structure
>If I want to get both DATA1 and DATA2 I can use a simple regex like :

It's a bad idea in the first place. XML is not a regular language, why would
you use regular expressions to parse it?

>Any help would be appreciated !

Use a tool that is designed to parse XML like e.g. any of the XML parser
modules on CPAN.

jue


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

Date: Thu, 27 Dec 2007 15:06:47 -0800 (PST)
From: patriknym@hotmail.com
Subject: Re: Regular Expression for XML Parsing
Message-Id: <87ddb3d9-e880-4193-a14f-8ca0b97899bd@j20g2000hsi.googlegroups.com>

On 27 Dec, 20:59, tushar.sax...@gmail.com wrote:
> Hi,
>
> I have a set of XML files from which I need to extract some data. The
> format of the file is as follows :
>
> <tag1>
>    <tag3>DATA1</tag3>
> </tag1>
>
> <tag2>
>    <tag3>DATA2</tag3>
> </tag2>
>
> I need to extract the DATA part of the xml structure
>
> Note : tag3 can be contained either within tag1 or tag2, but I need to
> extract data only from tag1. i.e. DATA1 should be extracted, but not
> DATA2
>
> If I want to get both DATA1 and DATA2 I can use a simple regex like :
>
> if (($_ =~ /<tag3>(\w+)<\/tag3>/g))
> {
>     print $1
>
> }
>
> But if I try to get only DATA1 (embedded within tag1) I try using
> something like this, but am unable to get it to work
>
> if (($_ =~ /<tag1>[\n\s\S\w\W]*<tag2>(\w+)<\/tag2>[\n\s\S\w\W]*<\/
> tag1>/g))
> {
>     print $1
>
> }
>
> In this second case, the match itself fails.
>
> Any help would be appreciated !

$/ = "";

while (<>) {
  if ( m{<tag1>.*?<tag3>(\w+)</tag3>.*?</tag1>}gs )
  {
    print "$1\n";
  }
}


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

Date: Fri, 28 Dec 2007 00:19:44 GMT
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Regular Expression for XML Parsing
Message-Id: <slrnfn8fss.hne.tadmc@tadmc30.sbcglobal.net>

tushar.saxena@gmail.com <tushar.saxena@gmail.com> wrote:

> I have a set of XML files from which I need to extract some data. The
> format of the file is as follows :
>
><tag1>
>    <tag3>DATA1</tag3>
></tag1>
>
><tag2>
>    <tag3>DATA2</tag3>
></tag2>


I thought you said you had an XML file.

That is not a valid XML file...


> I need to extract the DATA part of the xml structure
>
> Note : tag3 can be contained either within tag1 or tag2, but I need to
> extract data only from tag1. i.e. DATA1 should be extracted, but not
> DATA2
>
> If I want to get both DATA1 and DATA2 I can use a simple regex like :


Using a regular expression to "parse" a non-regular language is
fraught with peril, and nearly always a Bad Idea.

Use a module that understands XML for processing XML data.


> Any help would be appreciated !


Assuming that you have actual valid XML in $xml, then:

    use XML::Simple;

    my $ref = XMLin($xml);
    foreach my $child ( @{ $ref->{tag1} } ) {
       print "$child->{tag3}\n";
    }


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Fri, 28 Dec 2007 13:35:10 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Regular Expression for XML Parsing
Message-Id: <h9r9n3tuva2sgel1n2ovihgg92o1d46olq@4ax.com>

On Thu, 27 Dec 2007 12:59:12 -0800 (PST), tushar.saxena@gmail.com
wrote:

>Subject: Regular Expression for XML Parsing

Nope. Perhaps a Regex for XML Parsing, in the Perl 6 acceptation of a
"Regex" which is not assumed to be a "Regular Expression" any more.
You will have to wait for quite a while, though...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 27 Dec 2007 19:46:50 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: reopen the file
Message-Id: <a2cd45-vu5.ln1@osiris.mauzo.dyndns.org>


Quoth "vijay@iavian.com" <vijay@iavian.com>:
> open(MAPFILE, $FTP_MAPFILE);

Use three-arg open.
Use lexical filehandles.
Check the return value of open.

    open(my $MAPFILE, '<', $FTP_MAPFILE)
        or die "can't open '$FTP_MAPFILE': $!";

>  while(<MAPFILE>){
>       chop;

Don't use chop, use chomp instead.

>       ($user,$file) = split /=/;

Why aren't you using strict?

>       if(uc($user) eq uc($userid)){

It's generally better to normalise case with lc than with uc. Unicode
defines three cases (upper, lower and title), and while upper->lower and
title->lower are well-defined, title->upper isn't.

>          push(@files,$file);
>       }
>    }
>    close(MAPFILE);
> 
>    open(MAPFILE, $FTP_MAPFILE);
>    while(<MAPFILE>){
>       #do something;
>    }
> 
> In the above code i open the file twice to read . How do i do
> something without reopening the file

See perldoc -f seek.

Ben



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

Date: Thu, 27 Dec 2007 21:02:11 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: reopen the file
Message-Id: <87fxxn29fg.fsf@zeekat.nl>

Ben Morrow <ben@morrow.me.uk> writes:

> It's generally better to normalise case with lc than with uc. Unicode
> defines three cases (upper, lower and title), and while upper->lower and
> title->lower are well-defined, title->upper isn't.

Now that's a good suggestion I'd never heard.

Cheers,

Joost.


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

Date: Fri, 28 Dec 2007 11:51:53 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a  regular expression into $/ but it didn't work. What's wrong?)
Message-Id: <a50c4c79-d8d7-49cf-b033-f29874359d87@v4g2000hsf.googlegroups.com>

On Dec 28, 1:52=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:

> Actually, I've often run into the need for parallel edits like this,
> where you want to s/A/B/ and s/B/C but you don't want A to become C.
> With complex operations or operations you don't know in advance, proper
> ordering becomes impossible. =A0I usually handle it with function calls:
> s/[ABC]/replacement(\1)/e or something like that. =A0Is there a better
> approach anyone can recommend?
>

What does the above do? Shouldn't that be:
s/[ABC]/replacement( $1 )/e;

?

And could you please expound on "With complex operations or operations
you don't know in advance..."?
I don't see how you could avoid doing an inadvertent A->C if you did
multiple s/// out of order, unless you provided enough context for the
regex to work correctly.


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

Date: Fri, 28 Dec 2007 11:52:49 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a  regular expression into $/ but it didn't work. What's wrong?)
Message-Id: <96e8c1e5-927f-47bd-9253-cd95c1babbd3@f53g2000hsg.googlegroups.com>

On Dec 28, 2:51=A0pm, nolo contendere <simon.c...@fmr.com> wrote:
> On Dec 28, 1:52=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
>
> > Actually, I've often run into the need for parallel edits like this,
> > where you want to s/A/B/ and s/B/C but you don't want A to become C.
> > With complex operations or operations you don't know in advance, proper
> > ordering becomes impossible. =A0I usually handle it with function calls:=

> > s/[ABC]/replacement(\1)/e or something like that. =A0Is there a better
> > approach anyone can recommend?
>
> What does the above do? Shouldn't that be:
> s/[ABC]/replacement( $1 )/e;
>
> ?
>
> And could you please expound on "With complex operations or operations
> you don't know in advance..."?
> I don't see how you could avoid doing an inadvertent A->C if you did
> multiple s/// out of order, unless you provided enough context for the
> regex to work correctly.

Oh yeah, just saw Michele's post. I forgot the capturing parens,
should be:
s/([ABC])/replacement( $1 )/e;


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

Date: Fri, 28 Dec 2007 12:52:26 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
Message-Id: <86k5myzm6t.fsf_-_@lifelogs.com>

On Thu, 27 Dec 2007 21:35:11 +0000 Ben Morrow <ben@morrow.me.uk> wrote: 

BM> Quoth PerlFAQ Server <brian@stonehenge.com>:
>> 
>> 6.4: I put a regular expression into $/ but it didn't work. What's wrong?
>> 
>> Up to Perl 5.8.0, $/ has to be a string. This may change in 5.10, but
>> don't get your hopes up. Until then, you can use these examples if you

BM> s/8/10/; s/10/12/;

You want that backwards :)

Actually, I've often run into the need for parallel edits like this,
where you want to s/A/B/ and s/B/C but you don't want A to become C.
With complex operations or operations you don't know in advance, proper
ordering becomes impossible.  I usually handle it with function calls:
s/[ABC]/replacement(\1)/e or something like that.  Is there a better
approach anyone can recommend?

Thanks
Ted


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

Date: Fri, 28 Dec 2007 20:47:50 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
Message-Id: <0jkan39bdfmjl81n8sd7tdjfgpupkufbul@4ax.com>

On Fri, 28 Dec 2007 12:52:26 -0600, Ted Zlatanov <tzz@lifelogs.com>
wrote:

>BM> s/8/10/; s/10/12/;
>
>You want that backwards :)
>
>Actually, I've often run into the need for parallel edits like this,
>where you want to s/A/B/ and s/B/C but you don't want A to become C.
>With complex operations or operations you don't know in advance, proper
>ordering becomes impossible.  I usually handle it with function calls:
>s/[ABC]/replacement(\1)/e or something like that.  Is there a better

I believe you want capturing parens in the regex and $1 rather than \1
in the substitution.

>approach anyone can recommend?

Well, similar to yours, except not necessarily with /e (often a hash
is enough):

  s/([ABC])/$replacement{$1}/g;


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 28 Dec 2007 23:49:03 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
Message-Id: <slrnfnb2rf.s04.abigail@alexandra.abigail.be>

                                         _
Ted Zlatanov (tzz@lifelogs.com) wrote on VCCXXXII September MCMXCIII in
<URL:news:86k5myzm6t.fsf_-_@lifelogs.com>:
&&  On Thu, 27 Dec 2007 21:35:11 +0000 Ben Morrow <ben@morrow.me.uk> wrote: 
&&  
&&  BM> Quoth PerlFAQ Server <brian@stonehenge.com>:
&& >> 
&& >> 6.4: I put a regular expression into $/ but it didn't work. What's wrong?
&& >> 
&& >> Up to Perl 5.8.0, $/ has to be a string. This may change in 5.10, but
&& >> don't get your hopes up. Until then, you can use these examples if you
&&  
&&  BM> s/8/10/; s/10/12/;
&&  
&&  You want that backwards :)
&&  
&&  Actually, I've often run into the need for parallel edits like this,
&&  where you want to s/A/B/ and s/B/C but you don't want A to become C.
&&  With complex operations or operations you don't know in advance, proper
&&  ordering becomes impossible.  I usually handle it with function calls:
&&  s/[ABC]/replacement(\1)/e or something like that.  Is there a better
&&  approach anyone can recommend?


If A, B and C are just single characters, tr/AB/BC/ will do.

Otherwise, I'd do:

    my %replacement = (A => B, B => C);
    s/(A|B)/$replacement{$1}/g;


Abigail
-- 
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
           ${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'


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

Date: Fri, 28 Dec 2007 14:11:45 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <86ve6iy3y6.fsf@lifelogs.com>

On Fri, 28 Dec 2007 11:52:49 -0800 (PST) nolo contendere <simon.chao@fmr.com> wrote: 

nc> On Dec 28, 2:51 pm, nolo contendere <simon.c...@fmr.com> wrote:
>> On Dec 28, 1:52 pm, Ted Zlatanov <t...@lifelogs.com> wrote:
>> 
>> > Actually, I've often run into the need for parallel edits like this,
>> > where you want to s/A/B/ and s/B/C but you don't want A to become C.
>> > With complex operations or operations you don't know in advance, proper
>> > ordering becomes impossible.  I usually handle it with function calls:
>> > s/[ABC]/replacement(\1)/e or something like that.  Is there a better
>> > approach anyone can recommend?
>> 
>> What does the above do? Shouldn't that be:
>> s/[ABC]/replacement( $1 )/e;
>> 
>> ?
>> 
>> And could you please expound on "With complex operations or operations
>> you don't know in advance..."?
>> I don't see how you could avoid doing an inadvertent A->C if you did
>> multiple s/// out of order, unless you provided enough context for the
>> regex to work correctly.

nc> Oh yeah, just saw Michele's post. I forgot the capturing parens,
nc> should be:
nc> s/([ABC])/replacement( $1 )/e;

I forgot the parenthesis, but it doesn't change my question.  \1 works
like $1 in this case, I used it out of habit.

Look at my example.  When you are given a list of "X -> Y"
transformations, you don't know in advance how to order them so they
won't overlap (as in the A to B to C example).  You need to look through
the list.  The right ordering may not even be possible (if there's a
loop in the graph).  That's what I meant by "don't know in advance."  By
"complex" I mean that the overlap may not be obvious if the
replacement's output is not a simple function of the input.

Ted


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

Date: Fri, 28 Dec 2007 14:14:00 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <86r6h6y3uf.fsf@lifelogs.com>

On Fri, 28 Dec 2007 20:47:50 +0100 Michele Dondi <bik.mido@tiscalinet.it> wrote: 

>> approach anyone can recommend?

MD> Well, similar to yours, except not necessarily with /e (often a hash
MD> is enough):

MD>   s/([ABC])/$replacement{$1}/g;

That works too, much faster but it can only do static strings.  I didn't
think of it.  Thanks.

Ted


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

Date: Fri, 28 Dec 2007 12:22:41 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <46c0f53d-3ee7-460d-a33b-7e2c015af540@t1g2000pra.googlegroups.com>

On Dec 28, 3:11=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Fri, 28 Dec 2007 11:52:49 -0800 (PST) nolo contendere <simon.c...@fmr.c=
om> wrote:
>
> nc> On Dec 28, 2:51=A0pm, nolo contendere <simon.c...@fmr.com> wrote:
>
>
>
> >> On Dec 28, 1:52=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
>
> >> > Actually, I've often run into the need for parallel edits like this,
> >> > where you want to s/A/B/ and s/B/C but you don't want A to become C.
> >> > With complex operations or operations you don't know in advance, prop=
er
> >> > ordering becomes impossible. =A0I usually handle it with function cal=
ls:
> >> > s/[ABC]/replacement(\1)/e or something like that. =A0Is there a bette=
r
> >> > approach anyone can recommend?
>
> >> What does the above do? Shouldn't that be:
> >> s/[ABC]/replacement( $1 )/e;
>
> >> ?
>
> >> And could you please expound on "With complex operations or operations
> >> you don't know in advance..."?
> >> I don't see how you could avoid doing an inadvertent A->C if you did
> >> multiple s/// out of order, unless you provided enough context for the
> >> regex to work correctly.
>
> nc> Oh yeah, just saw Michele's post. I forgot the capturing parens,
> nc> should be:
> nc> s/([ABC])/replacement( $1 )/e;
>
> I forgot the parenthesis, but it doesn't change my question. =A0\1 works
> like $1 in this case, I used it out of habit.
>
> Look at my example. =A0When you are given a list of "X -> Y"
> transformations, you don't know in advance how to order them so they
> won't overlap (as in the A to B to C example). =A0You need to look through=

> the list. =A0The right ordering may not even be possible (if there's a
> loop in the graph). =A0That's what I meant by "don't know in advance." =A0=
By
> "complex" I mean that the overlap may not be obvious if the
> replacement's output is not a simple function of the input.
>

Ahh, gotcha. So you're talking about more of a line-by-line processing
approach than a multiple s/// on the same string.



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

Date: 29 Dec 2007 00:23:55 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <slrnfnb4sr.s04.abigail@alexandra.abigail.be>

                                         _
Ted Zlatanov (tzz@lifelogs.com) wrote on VCCXXXII September MCMXCIII in
<URL:news:86r6h6y3uf.fsf@lifelogs.com>:
))  On Fri, 28 Dec 2007 20:47:50 +0100 Michele Dondi <bik.mido@tiscalinet.it> wrote: 
))  
)) >> approach anyone can recommend?
))  
))  MD> Well, similar to yours, except not necessarily with /e (often a hash
))  MD> is enough):
))  
))  MD>   s/([ABC])/$replacement{$1}/g;
))  
))  That works too, much faster but it can only do static strings.  I didn't
))  think of it.  Thanks.


With 5.10, you can do it with A and B patterns:

    use 5.010;
    our $REGMARK;
    my %replacement = qw [X B Y C];
    $_ = "AABDAAABBE";
    s/(*:X)A(?{})|(*:Y)B/$replacement{$REGMARK}/g;
    say;
    __END__
    BCDBCE


Note that the (?{}) is there to prevent a bug from triggering.


Abigail
-- 
print v74.117.115.116.32, v97.110.111.116.104.101.114.32,
      v80.101.114.108.32, v72.97.99.107.101.114.10;


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

Date: Sat, 29 Dec 2007 14:45:17 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: s/A/B/ and s/B/C/ but don't want A -> C
Message-Id: <fl5mi6.b8.1@news.isolution.nl>

Abigail schreef:

>     my %replacement = (A => B, B => C);
>     s/(A|B)/$replacement{$1}/g;

If string-A can ever be a subpattern of string-B, then you need to add a
"longest first" approach.

$ echo "AABABA" | perl -wpe '
  BEGIN{ %repl = (A => B, AB => C); }
  s/(A|AB)/$repl{$1}/g;
'
BBBBBB

$ echo "AABABA" | perl -wpe '
  BEGIN{ %repl = (A => B, AB => C); }
  s/(AB|A)/$repl{$1}/g;  # longest first
'
BCCB

(or use a different regex-engine :)

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Fri, 28 Dec 2007 17:37:59 GMT
From: Richard Thomas <newsuser@dicksonlife.com>
Subject: Specifying options for Net::SFTP
Message-Id: <2ccan31ctv3os344ddrq771tng7frojmcb@4ax.com>

We are having issues when an automated file transfer process hangs
when using net::SFTP. This causes the whole process to hang and a
whole bunch of headaches ensue. We need to be able to give up on the
connection and carry on. I have tried adding timeout options to the
SFTP connection but they don't appear to be having any effect (The
process was just now hung up for over 32 hours). Can someone confirm
I'm using the parameters correctly?

$sftp=Net::SFTP->new ($site,(user     => $username,
                             password => $password,
                             debug => 1,
                             ssh_args => [ options => ["SetupTimeOut
300", "ServerAliveInterval 300", "ServerAliveCountMax 3"]],
       )) or die "Problem connecting to SFTP server. $!\n";

If it makes any difference, here is what the debug output of a hung
connection looks like:

Reading configuration data /home/user/.ssh/config
Reading configuration data /etc/ssh_config
Connecting to sftp.server.com, port 22.
Remote version string: SSH-2.0-5.1.0.558 SSH Tectia Server
Remote protocol version 2.0, remote software version 5.1.0.558 SSH
Tectia Server
Net::SSH::Perl Version 1.30, protocol version 2.0.
No compat match: 5.1.0.558 SSH Tectia Server
Connection established.
Sent key-exchange init (KEXINIT), wait response.

And there it hangs.


Any help much appreciated.

Thanks

Rich
-- 
If you squeeze my lizard
I'll put my snake on you
I'm a romantic adventure
And I'm a reptile too


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

Date: Fri, 28 Dec 2007 09:46:15 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Specifying options for Net::SFTP
Message-Id: <1fe4bbac-303b-4637-98cb-ded25751400c@i29g2000prf.googlegroups.com>

On Dec 28, 9:37 am, Richard Thomas <newsu...@dicksonlife.com> wrote:
> We are having issues when an automated file transfer process hangs
> when using net::SFTP. This causes the whole process to hang and a
> whole bunch of headaches ensue. We need to be able to give up on the
> connection and carry on. I have tried adding timeout options to the
> SFTP connection but they don't appear to be having any effect (The
> process was just now hung up for over 32 hours). Can someone confirm
> I'm using the parameters correctly?
>
> $sftp=Net::SFTP->new ($site,(user     => $username,
>                              password => $password,
>                              debug => 1,
>                              ssh_args => [ options => ["SetupTimeOut
> 300", "ServerAliveInterval 300", "ServerAliveCountMax 3"]],
>        )) or die "Problem connecting to SFTP server. $!\n";
>
Try changing it to this (note the use of the { } braces instead of ( )

$sftp=Net::SFTP->new ($site,{user     => $username,
                             password => $password,
                             debug => 1,
                             ssh_args => [ options => ["SetupTimeOut
300", "ServerAliveInterval 300", "ServerAliveCountMax 3"]],
       }) or die "Problem connecting to SFTP server. $!\n";


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

Date: Fri, 28 Dec 2007 18:23:14 GMT
From: Richard Thomas <newsuser@dicksonlife.com>
Subject: Re: Specifying options for Net::SFTP
Message-Id: <6ffan3pmm15qpl3fqfstj73u7ggt1lufkp@4ax.com>

On Fri, 28 Dec 2007 09:46:15 -0800 (PST), Ron Bergin <rkb@i.frys.com>
wrote:

>Try changing it to this (note the use of the { } braces instead of ( )
>
>$sftp=Net::SFTP->new ($site,{user     => $username,
>                             password => $password,
>                             debug => 1,
>                             ssh_args => [ options => ["SetupTimeOut
>300", "ServerAliveInterval 300", "ServerAliveCountMax 3"]],
>       }) or die "Problem connecting to SFTP server. $!\n";

Well, the login itself usually works fine, this problem occurs
probably only one time in many hundreds. It's the passing of the
timeout options I'm not sure of.

Rich
-- 
If you squeeze my lizard
I'll put my snake on you
I'm a romantic adventure
And I'm a reptile too


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1155
***************************************


home help back first fref pref prev next nref lref last post