[29436] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 680 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 25 16:10:21 2007

Date: Wed, 25 Jul 2007 13:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 25 Jul 2007     Volume: 11 Number: 680

Today's topics:
    Re: @arts <v.ronans@no.where.nospam>
    Re: @arts <bik.mido@tiscalinet.it>
        calling a script with arguments <jwilson@exeter.edu>
    Re: calling a script with arguments anno4000@radom.zrz.tu-berlin.de
    Re: calling a script with arguments <jurgenex@hotmail.com>
    Re: calling a script with arguments <mritty@gmail.com>
    Re: calling a script with arguments <jwilson@exeter.edu>
    Re: calling a script with arguments <mritty@gmail.com>
    Re: calling a script with arguments <noreply@gunnar.cc>
    Re: filehandle, read lines xhoster@gmail.com
        I am giving up perl because of assholes on clpm -- swit Martha_Jones@tx.net
        match string by re using some pattern <frytaz@gmail.com>
    Re: match string by re using some pattern anno4000@radom.zrz.tu-berlin.de
    Re: match string by re using some pattern <mritty@gmail.com>
    Re: match string by re using some pattern anno4000@radom.zrz.tu-berlin.de
    Re: match string by re using some pattern <frytaz@gmail.com>
    Re: match string by re using some pattern <frytaz@gmail.com>
    Re: match string by re using some pattern <mritty@gmail.com>
    Re: match string by re using some pattern <frytaz@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 25 Jul 2007 10:47:44 -0700
From: "Vronans" <v.ronans@no.where.nospam>
Subject: Re: @arts
Message-Id: <Yr-dnfR4jtxfETrbnZ2dnUVZ_tWtnZ2d@wavecable.com>

Michele Dondi wrote:
> On Tue, 24 Jul 2007 15:17:58 -0700, "Vronans" wrote:

>> Michele Dondi wrote:

(Please don't leave quotes without their *applicable* attributions.
 It can make quote tracing difficult and is inconsiderate. There
 is a good reason why it is common practice to attribute quotations.)

>>> In fact, nothing useful is being added to this thread since you
>>> poo^Hpped in
>>
>> Oh, and once again you owe no blame what so ever to that, right?
>
> Yes I have,

Where? Though, if you really feel you have and I have missed it, then 
feel free to cite an instance. Otherwise I'll take it as an admission 
that no such quote exists.



> but I won't any more: *PLONK*.

Wow, you are just the epitome of maturity, aren't you? Sigh... classic 
attempt to force a win, in your favor, of the argument at hand. Also a 
classic UseNet tactic*, and nothing new for this NG certainly. 
Personally, I find it to be rather childish, like plugging one's own 
ears while simultaneously yelling back, especially when you know you 
have lost.

Just face reality. You are clearly in the wrong in this argument, 
concerning proper quote attributions. It wont kill you to say something 
to the effect of, "I may have been wrong about that", despite to the 
common attitude of some regulars to the contrary.





* There is nothing wrong with kill-file-ing, there just never seems to 
be a good reason to publicly announce it, other than to display your 
self importance to the world.

It makes about as much sense as using symrefs over hashes in general 
practice.




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

Date: Wed, 25 Jul 2007 21:18:55 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: @arts
Message-Id: <qs6fa352ekfsgir4d2mesmk9rhg8ejgppd@4ax.com>

On Wed, 25 Jul 2007 10:47:44 -0700, "Vronans"
<v.ronans@no.where.nospam> wrote:

>>>> In fact, nothing useful is being added to this thread since you
>>>> poo^Hpped in
>>>
>>> Oh, and once again you owe no blame what so ever to that, right?
>>
>> Yes I have,
>
>Where? Though, if you really feel you have and I have missed it, then 

No, that's not what meant. Apologies: you said "you owe no blame what
so ever to that" and I meant to reply "yes I do owe much blame to
that". Thus I should have written "I do", I wrote "I have" instead,
possibly out of English not being my native language.

>feel free to cite an instance. Otherwise I'll take it as an admission 
>that no such quote exists.

In fact, no such quote exists because I meant something completely
different altogher: I do owe much blame to the fact that nothing
useful is being added to this thread since you poo^Hpped in exactly
because of my choice to reply you in the first place and because of my
insistence in doing so. Had I silently killfiled you, then I would
avoided all this, you would have been so happy to think that I was too
ashamed to reply and of having won your tiny childish crusade, and
world would have been a nicer place.

>> but I won't any more: *PLONK*.
>
>Wow, you are just the epitome of maturity, aren't you? Sigh... classic 

No, no, no, did I ever claim to be mature? Since you seem so keen on
searches, just show me an instance of me saying so, with proper
attributions, I recommend!

In fact I'm very immature: I've had the text of Tom Wait's "I don't
wanna grow up" for years on the side of my desk.

Amongst the many possible forms of cancer available I even "chose" one
that is a typical infantry tumor - well, not really: it's rare even
then. So please do not put words in my mouth.

>attempt to force a win, in your favor, of the argument at hand. Also a 

No, no, no, you won. I'm a loser. I already told you I have cancer:
that doesn't make for a very successful life.

I killfiled you for the simple reason that I think you're a useless
idiot. (There are idiots that for some reasons turn out to be useful.)
You're only making me lose my time, and you seem to like losing yours.
I'm convinced of being right and you're convinced of being right:
there's nothing each of us could ever say to convert the other, and we
could go on for eons - something that I've neither the will nor the
time to do. Last, there's no useful contributions of yours to the
group that I can remember so I can happily killfile your with no
regrets. (I'm not claiming that you made none, just that I can't
recall any - if I got into an argument like this with e.g. Anno, then
I couldn't killfile him anyway because of his precious interventions,
but I can't remember having seen your name before a few days ago.)

>Just face reality. You are clearly in the wrong in this argument, 
>concerning proper quote attributions. It wont kill you to say something 
>to the effect of, "I may have been wrong about that", despite to the 
>common attitude of some regulars to the contrary.

Till the *only* person to ever complain is "Vronans" I won't bother.
If someone whom I respect will, then I will take into accounts what he
or she will have to say.

>* There is nothing wrong with kill-file-ing, there just never seems to 
>be a good reason to publicly announce it, other than to display your 
>self importance to the world.

Ok, so I'm sorry. No, really: I take much into account your opinion,
so I guarantee that I will never ever killfile you publicly announcing
having done so. Now, can I hope that you changed your identity once
and that you won't do many more time in the future?


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: Wed, 25 Jul 2007 07:13:51 -0700
From:  jpw <jwilson@exeter.edu>
Subject: calling a script with arguments
Message-Id: <1185372831.990179.70200@57g2000hsv.googlegroups.com>

I have a script that creates and XML record and then posts it to a
url.  I'd like to be able to build the XML record separately and just
"pass" it to the script.  The script needs to be excuted at the shell
prompt.  So, I'd like to be able to execute:  ./myscript
<path&filename to xml file>.

How, from within, the script to I get the xml file?  In other
programming environments, I have used the @sentence command which
provides the script with the entire line it was executed with.



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

Date: 25 Jul 2007 14:18:30 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: calling a script with arguments
Message-Id: <5gp4dmF3i3odeU2@mid.dfncis.de>

jpw  <jwilson@exeter.edu> wrote in comp.lang.perl.misc:
> I have a script that creates and XML record and then posts it to a
> url.  I'd like to be able to build the XML record separately and just
> "pass" it to the script.  The script needs to be excuted at the shell
> prompt.  So, I'd like to be able to execute:  ./myscript
> <path&filename to xml file>.
> 
> How, from within, the script to I get the xml file?  In other
> programming environments, I have used the @sentence command which
> provides the script with the entire line it was executed with.
> 

perldoc perlvar, look for @ARGV.

Anno


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

Date: Wed, 25 Jul 2007 14:19:56 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: calling a script with arguments
Message-Id: <g_Ipi.4495$Gs4.65@trndny05>

jpw wrote:
> I have a script that creates and XML record and then posts it to a
> url.  I'd like to be able to build the XML record separately and just
> "pass" it to the script.  The script needs to be excuted at the shell
> prompt.  So, I'd like to be able to execute:  ./myscript
> <path&filename to xml file>.
>
> How, from within, the script to I get the xml file?

perldoc -f open

> In other
> programming environments, I have used the @sentence command which
> provides the script with the entire line it was executed with.

Are you just looking for @ARGV (details see perldoc perlvar)?

jue 




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

Date: Wed, 25 Jul 2007 07:37:06 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: calling a script with arguments
Message-Id: <1185374226.328463.280490@19g2000hsx.googlegroups.com>

On Jul 25, 10:13 am, jpw <jwil...@exeter.edu> wrote:
> I have a script that creates and XML record and then posts it to a
> url.  I'd like to be able to build the XML record separately and just
> "pass" it to the script.  The script needs to be excuted at the shell
> prompt.  So, I'd like to be able to execute:  ./myscript
> <path&filename to xml file>.
>
> How, from within, the script to I get the xml file?  In other
> programming environments, I have used the @sentence command which
> provides the script with the entire line it was executed with.

Anno and Jue already told you that you're looking for the @ARGV array,
but I am *very* curious what you mean by "the @sentence command".
There is no such command.  @sentence is a user-defined array that has
no special meaning whatsoever.  Can you please explain what you meant
by this?

Paul Lalli



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

Date: Wed, 25 Jul 2007 08:16:30 -0700
From:  jpw <jwilson@exeter.edu>
Subject: Re: calling a script with arguments
Message-Id: <1185376590.973638.98040@k79g2000hse.googlegroups.com>

On Jul 25, 10:37 am, Paul Lalli <mri...@gmail.com> wrote:
> On Jul 25, 10:13 am, jpw <jwil...@exeter.edu> wrote:
>
> > I have a script that creates and XML record and then posts it to a
> > url.  I'd like to be able to build the XML record separately and just
> > "pass" it to the script.  The script needs to be excuted at the shell
> > prompt.  So, I'd like to be able to execute:  ./myscript
> > <path&filename to xml file>.
>
> > How, from within, the script to I get the xml file?  In other
> > programming environments, I have used the @sentence command which
> > provides the script with the entire line it was executed with.
>
> Anno and Jue already told you that you're looking for the @ARGV array,
> but I am *very* curious what you mean by "the @sentence command".
> There is no such command.  @sentence is a user-defined array that has
> no special meaning whatsoever.  Can you please explain what you meant
> by this?
>
> Paul Lalli

Thank you for the replies.  While ARGV does provide me the string
value of the command line, as opposed to the actual "content"  of the
xml file.  Presumably I would then have to *read* the file in to a
variable to then be posted to the url.  Incidently, I don't know how
to do that either.

Regarding @sentence.  Sorry for the confusion.  I should have just
said "commandline arguments".  The reference to @sentence was merely
an example from another programing language (namely, Unidata).   It's
has the same function as ARGV in PERL.

On to research reading files and assigning them to an array variable
(any knowledge of this?)


John



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

Date: Wed, 25 Jul 2007 08:34:19 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: calling a script with arguments
Message-Id: <1185377659.999042.70450@19g2000hsx.googlegroups.com>

On Jul 25, 11:16 am, jpw <jwil...@exeter.edu> wrote:

> Thank you for the replies.  While ARGV does provide me the string
> value of the command line, as opposed to the actual "content"  of the
> xml file.  Presumably I would then have to *read* the file in to a
> variable to then be posted to the url.  Incidently, I don't know how
> to do that either.

Jue gave you that answer too.

perldoc -f open
perldoc -f readline
perldoc perlop

Paul Lalli



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

Date: Wed, 25 Jul 2007 17:49:44 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calling a script with arguments
Message-Id: <5gp9v3F3gsscqU1@mid.individual.net>

jpw wrote:
> While ARGV does provide me the string
> value of the command line, as opposed to the actual "content"  of the
> xml file.  Presumably I would then have to *read* the file in to a
> variable to then be posted to the url.  Incidently, I don't know how
> to do that either.

     http://perldoc.perl.org/perlintro.html

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 25 Jul 2007 15:46:32 GMT
From: xhoster@gmail.com
Subject: Re: filehandle, read lines
Message-Id: <20070725114633.630$yR@newsreader.com>

roy.schultheiss@googlemail.com wrote:
> Thank you both for your answers.
>
> I tried to split a file into smaller parts to start multiple processes
> working on it. So the 1st process starts on line 1 - 10_000_000 and
> 2nd process from 10_000_001 to 20_000_000 etc.

I generally prefer to "stripe" rather than "split" files, when I can
get away with it.  So if I wanted to run 4 jobs, I would start 4 jobs,
each one given a $task from 0 to 3.

while (<>) {
  next unless $. % 4 == $task;
  #....
};


This way, you don't need to pre-compute anything based on the size of the
file.  If you have an IO bottleneck, this could be either better or worse,
IO-wise, than the splitting method depending on the exact details of your
IO system.


> I'll use seek to set the Position of the handle.

Be aware that you will likely put you into the middle of a line.  So you
must burn that line before you start on the next "real" one.  And you need
to arrange that this burned partial line gets processed correctly by one
of the other task.  That is not terribly hard to do, but it is also easy
to screw up.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Wed, 25 Jul 2007 14:45:29 -0500
From: Martha_Jones@tx.net
Subject: I am giving up perl because of assholes on clpm -- switching to Python
Message-Id: <0Y2dnTFHdYnENTrbnZ2dnUVZ_vrinZ2d@giganews.com>

Python is a better language, with php support, anyway, but I am fed up
with attitudes of comp.lang.perl.misc. Assholes in this newsgroup ruin
Perl experience for everyone. Instead of being helpful, snide remarks,
back-biting, scare tactings, and so on proliferate and self
reinforce. All honest people have left this sad newsgroup. Buy bye,
assholes, I am not going to miss you!!!

Martha


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

Date: Wed, 25 Jul 2007 06:44:28 -0700
From:  "frytaz@gmail.com" <frytaz@gmail.com>
Subject: match string by re using some pattern
Message-Id: <1185371068.166021.225390@k79g2000hse.googlegroups.com>

Hi, I'm trying to match few strings using some pattern
for instance i have in my file

#one# some text #two# more t*xt #three#
#two# text #one# some text #three#

and in perl
 ...
$re =~ s/#one#/\(\.\+\?\)/;
$re =~ s/#two#/\(\.\+\?\)/;
$re =~ s/#three#/\(\.\+\?\)/;

if ($line =~ m/^$re/) {
 $one = $1;
 $two = $2;
 $three = $3;
}

It's all right for first file line when #one# #two# #three# are in
order,
How i can check which word was it in line before replacing it by (.
+?) ??
Or maybe there is some different way to do this :)

Please help
Thanks



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

Date: 25 Jul 2007 14:17:16 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: match string by re using some pattern
Message-Id: <5gp4bcF3i3odeU1@mid.dfncis.de>

frytaz@gmail.com <frytaz@gmail.com> wrote in comp.lang.perl.misc:
> Hi, I'm trying to match few strings using some pattern
> for instance i have in my file
> 
> #one# some text #two# more t*xt #three#
> #two# text #one# some text #three#
> 
> and in perl
> ...
> $re =~ s/#one#/\(\.\+\?\)/;
> $re =~ s/#two#/\(\.\+\?\)/;
> $re =~ s/#three#/\(\.\+\?\)/;

What did $re contain before the replacements?

Why do you have to apply substitutions on the regex instead of
specifying it right away?

> if ($line =~ m/^$re/) {
>  $one = $1;
>  $two = $2;
>  $three = $3;
> }

Since we don't know what $re contains at this point, there's no way
to assess what it might be doing.

> It's all right for first file line when #one# #two# #three# are in
> order,

Please explain what "all right" means.  I'm sure it's obvious to you,
but it isn't to us.

> How i can check which word was it in line before replacing it by (.
> +?) ??
> Or maybe there is some different way to do this :)

What is "this"?

You have given us (incomplete) code that, you say, doesn't do what
you want.  Without an explanation from you, how are we supposed to
guess what you want?

Anno


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

Date: Wed, 25 Jul 2007 07:19:54 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: match string by re using some pattern
Message-Id: <1185373194.125088.192320@l70g2000hse.googlegroups.com>

On Jul 25, 9:44 am, "fry...@gmail.com" <fry...@gmail.com> wrote:
> Hi, I'm trying to match few strings using some pattern
> for instance i have in my file
>
> #one# some text #two# more t*xt #three#
> #two# text #one# some text #three#
>
> and in perl
> ...
> $re =~ s/#one#/\(\.\+\?\)/;
> $re =~ s/#two#/\(\.\+\?\)/;
> $re =~ s/#three#/\(\.\+\?\)/;

No need for all those backslashes.  The replacement part of a s/// is
just a string, and none of those characters are special in a string.

>
> if ($line =~ m/^$re/) {
>  $one = $1;
>  $two = $2;
>  $three = $3;
>
> }
>
> It's all right for first file line when #one# #two# #three# are in
> order,
> How i can check which word was it in line before replacing it by (.
> +?) ??
> Or maybe there is some different way to do this :)

You're basically trying to use a variable as a variable name, albeit
in a different way than most people attempt to do so.  Regardless, the
advice in `perldoc -q "variable name"` still holds.  Please read it.

One solution would be to save the ordering of "one", "two", "three" as
you're replacing them, and then use that ordering in your
replacement.  Rather than setting the variables $one, $two, $three,
instead create a hash that has corresponding keys 'one', 'two', and
'three'.  Here's a short-but-complete example:

#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;

my $re = '#one# some text #two# more t*xt #three#';
my $re2 = '#two# text #one# some text #three#';

my (@pos, @pos2);
while ($re =~ s/#(one|two|three)#/(.+?)/) {
    push @pos, $1;
}
while ($re2 =~ s/#(one|two|three)#/(.+?)/) {
    push @pos2, $1;
}
my (%h1, %h2);
my $line = "foo some text bar more tttxt baz";
if ($line =~ m/^$re$/) {
    $h1{$pos[0]} = $1;
    $h1{$pos[1]} = $2;
    $h1{$pos[2]} = $3;
}
my $line2 = "foo text bar some text baz";
if ($line2 =~ m/^$re2$/) {
    $h2{$pos2[0]} = $1;
    $h2{$pos2[1]} = $2;
    $h2{$pos2[2]} = $3;
}

print Dumper(\%h1, \%h2);
__END__

$VAR1 = {
          'three' => 'baz',
          'one' => 'foo',
          'two' => 'bar'
        };
$VAR2 = {
          'three' => 'baz',
          'one' => 'bar',
          'two' => 'foo'
        };


Hope that helps,
Paul Lalli



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

Date: 25 Jul 2007 14:52:41 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: match string by re using some pattern
Message-Id: <5gp6dpF3hpnrcU1@mid.dfncis.de>

Paul Lalli  <mritty@gmail.com> wrote in comp.lang.perl.misc:
> On Jul 25, 9:44 am, "fry...@gmail.com" <fry...@gmail.com> wrote:
> > Hi, I'm trying to match few strings using some pattern
> > for instance i have in my file
> >
> > #one# some text #two# more t*xt #three#
> > #two# text #one# some text #three#
> >
> > and in perl
> > ...
> > $re =~ s/#one#/\(\.\+\?\)/;
> > $re =~ s/#two#/\(\.\+\?\)/;
> > $re =~ s/#three#/\(\.\+\?\)/;
> 
> No need for all those backslashes.  The replacement part of a s/// is
> just a string, and none of those characters are special in a string.
> 
> >
> > if ($line =~ m/^$re/) {
> >  $one = $1;
> >  $two = $2;
> >  $three = $3;
> >
> > }
> >
> > It's all right for first file line when #one# #two# #three# are in
> > order,
> > How i can check which word was it in line before replacing it by (.
> > +?) ??
> > Or maybe there is some different way to do this :)
> 
> You're basically trying to use a variable as a variable name, albeit
> in a different way than most people attempt to do so.  Regardless, the
> advice in `perldoc -q "variable name"` still holds.  Please read it.

Ah, you decoded the mystery question.  Congrats.

> One solution would be to save the ordering of "one", "two", "three" as
> you're replacing them, and then use that ordering in your
> replacement.  Rather than setting the variables $one, $two, $three,
> instead create a hash that has corresponding keys 'one', 'two', and
> 'three'.

Once you have the hash, you can even set the variables.  Nothing wrong
with that.

> Here's a short-but-complete example:

[snip]

Here is my take.  I'm assuming that the delimiter "#" can't appear in
the text:

    while ( <DATA> ) {
        print;
        my %h = /#(one|two|three)#([^#\n]*)/g;
        my ( $one, $two, $three) = @h{ qw( one two three)};
        # do things with $one, $two, $three
        print "one: '$one', two: '$two', three: '$three'\n";
    }

    __DATA__
    #one# some text #two# more t*xt #three#
    #two# text #one# some text #three#

Anno


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

Date: Wed, 25 Jul 2007 08:08:07 -0700
From:  "frytaz@gmail.com" <frytaz@gmail.com>
Subject: Re: match string by re using some pattern
Message-Id: <1185376087.102152.79730@k79g2000hse.googlegroups.com>

On Jul 25, 4:19 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Jul 25, 9:44 am, "fry...@gmail.com" <fry...@gmail.com> wrote:
>
> > Hi, I'm trying to match few strings using some pattern
> > for instance i have in my file
>
> > #one# some text #two# more t*xt #three#
> > #two# text #one# some text #three#
>
> > and in perl
> > ...
> > $re =~ s/#one#/\(\.\+\?\)/;
> > $re =~ s/#two#/\(\.\+\?\)/;
> > $re =~ s/#three#/\(\.\+\?\)/;
>
> No need for all those backslashes.  The replacement part of a s/// is
> just a string, and none of those characters are special in a string.
>
>
>
> > if ($line =~ m/^$re/) {
> >  $one = $1;
> >  $two = $2;
> >  $three = $3;
>
> > }
>
> > It's all right for first file line when #one# #two# #three# are in
> > order,
> > How i can check which word was it in line before replacing it by (.
> > +?) ??
> > Or maybe there is some different way to do this :)
>
> You're basically trying to use a variable as a variable name, albeit
> in a different way than most people attempt to do so.  Regardless, the
> advice in `perldoc -q "variable name"` still holds.  Please read it.
>
> One solution would be to save the ordering of "one", "two", "three" as
> you're replacing them, and then use that ordering in your
> replacement.  Rather than setting the variables $one, $two, $three,
> instead create a hash that has corresponding keys 'one', 'two', and
> 'three'.  Here's a short-but-complete example:
>
> #!/usr/bin/env perl
> use strict;
> use warnings;
> use Data::Dumper;
>
> my $re = '#one# some text #two# more t*xt #three#';
> my $re2 = '#two# text #one# some text #three#';
>
> my (@pos, @pos2);
> while ($re =~ s/#(one|two|three)#/(.+?)/) {
>     push @pos, $1;}
>
> while ($re2 =~ s/#(one|two|three)#/(.+?)/) {
>     push @pos2, $1;}
>
> my (%h1, %h2);
> my $line = "foo some text bar more tttxt baz";
> if ($line =~ m/^$re$/) {
>     $h1{$pos[0]} = $1;
>     $h1{$pos[1]} = $2;
>     $h1{$pos[2]} = $3;}
>
> my $line2 = "foo text bar some text baz";
> if ($line2 =~ m/^$re2$/) {
>     $h2{$pos2[0]} = $1;
>     $h2{$pos2[1]} = $2;
>     $h2{$pos2[2]} = $3;
>
> }
>
> print Dumper(\%h1, \%h2);
> __END__
>
> $VAR1 = {
>           'three' => 'baz',
>           'one' => 'foo',
>           'two' => 'bar'
>         };
> $VAR2 = {
>           'three' => 'baz',
>           'one' => 'bar',
>           'two' => 'foo'
>         };
>
> Hope that helps,
> Paul Lalli

Thank You very much Paul Lalli



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

Date: Wed, 25 Jul 2007 18:05:27 -0000
From:  "frytaz@gmail.com" <frytaz@gmail.com>
Subject: Re: match string by re using some pattern
Message-Id: <1185386727.485692.318640@d55g2000hsg.googlegroups.com>

On Jul 25, 4:19 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Jul 25, 9:44 am, "fry...@gmail.com" <fry...@gmail.com> wrote:
>
> > Hi, I'm trying to match few strings using some pattern
> > for instance i have in my file
>
> > #one# some text #two# more t*xt #three#
> > #two# text #one# some text #three#
>
> > and in perl
> > ...
> > $re =~ s/#one#/\(\.\+\?\)/;
> > $re =~ s/#two#/\(\.\+\?\)/;
> > $re =~ s/#three#/\(\.\+\?\)/;
>
> No need for all those backslashes.  The replacement part of a s/// is
> just a string, and none of those characters are special in a string.
>
>
>
> > if ($line =~ m/^$re/) {
> >  $one = $1;
> >  $two = $2;
> >  $three = $3;
>
> > }
>
> > It's all right for first file line when #one# #two# #three# are in
> > order,
> > How i can check which word was it in line before replacing it by (.
> > +?) ??
> > Or maybe there is some different way to do this :)
>
> You're basically trying to use a variable as a variable name, albeit
> in a different way than most people attempt to do so.  Regardless, the
> advice in `perldoc -q "variable name"` still holds.  Please read it.
>
> One solution would be to save the ordering of "one", "two", "three" as
> you're replacing them, and then use that ordering in your
> replacement.  Rather than setting the variables $one, $two, $three,
> instead create a hash that has corresponding keys 'one', 'two', and
> 'three'.  Here's a short-but-complete example:
>
> #!/usr/bin/env perl
> use strict;
> use warnings;
> use Data::Dumper;
>
> my $re = '#one# some text #two# more t*xt #three#';
> my $re2 = '#two# text #one# some text #three#';
>
> my (@pos, @pos2);
> while ($re =~ s/#(one|two|three)#/(.+?)/) {
>     push @pos, $1;}
>
> while ($re2 =~ s/#(one|two|three)#/(.+?)/) {
>     push @pos2, $1;}
>
> my (%h1, %h2);
> my $line = "foo some text bar more tttxt baz";
> if ($line =~ m/^$re$/) {
>     $h1{$pos[0]} = $1;
>     $h1{$pos[1]} = $2;
>     $h1{$pos[2]} = $3;}
>
> my $line2 = "foo text bar some text baz";
> if ($line2 =~ m/^$re2$/) {
>     $h2{$pos2[0]} = $1;
>     $h2{$pos2[1]} = $2;
>     $h2{$pos2[2]} = $3;
>
> }
>
> print Dumper(\%h1, \%h2);
> __END__
>
> $VAR1 = {
>           'three' => 'baz',
>           'one' => 'foo',
>           'two' => 'bar'
>         };
> $VAR2 = {
>           'three' => 'baz',
>           'one' => 'bar',
>           'two' => 'foo'
>         };
>
> Hope that helps,
> Paul Lalli

How I could recognize those patterns #one# #two# #three#

Can i do it like in c#, for instance

$match =~ s/#one#/(?<one>.*?)/;
$match =~ s/#two#/(?<two>.*?)/;
$match =~ s/#three#/(?<three>.*?)/;

then

$one = ${one};
$two = ${two};
$three = ${three};

But that doesn't work...

Thanks



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

Date: Wed, 25 Jul 2007 11:14:18 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: match string by re using some pattern
Message-Id: <1185387258.898749.297680@b79g2000hse.googlegroups.com>

On Jul 25, 2:05 pm, "fry...@gmail.com" <fry...@gmail.com> wrote:
> How I could recognize those patterns #one# #two# #three#
>
> Can i do it like in c#, for instance
>
> $match =~ s/#one#/(?<one>.*?)/;
> $match =~ s/#two#/(?<two>.*?)/;
> $match =~ s/#three#/(?<three>.*?)/;
>
> then
>
> $one = ${one};
> $two = ${two};
> $three = ${three};
>
> But that doesn't work...

Not until Perl 5.10, no it doesn't.

We've already given you an implementable solution.  What issue are you
still having with it?

Paul Lalli



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

Date: Wed, 25 Jul 2007 19:15:30 -0000
From:  "frytaz@gmail.com" <frytaz@gmail.com>
Subject: Re: match string by re using some pattern
Message-Id: <1185390930.892063.159110@l70g2000hse.googlegroups.com>

On Jul 25, 8:14 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Jul 25, 2:05 pm, "fry...@gmail.com" <fry...@gmail.com> wrote:
>
> > How I could recognize those patterns #one# #two# #three#
>
> > Can i do it like in c#, for instance
>
> > $match =~ s/#one#/(?<one>.*?)/;
> > $match =~ s/#two#/(?<two>.*?)/;
> > $match =~ s/#three#/(?<three>.*?)/;
>
> > then
>
> > $one = ${one};
> > $two = ${two};
> > $three = ${three};
>
> > But that doesn't work...
>
> Not until Perl 5.10, no it doesn't.
>
> We've already given you an implementable solution.  What issue are you
> still having with it?
>
> Paul Lalli

There is an issue when, theres two lines in file

1 some #one# test #two# text #three#
2 some #two# test #one# text #three#

then after replace by s/#(one|two|three)#/(.+?)/

1 some (.+?) test (.+?) text (.+?)
2 some (.+?) text (.+?) text (.+?)

then if I'm trying to match it with

some O!N!E test T!W!O text T!H!R!E!E

script will work fine only for 1st file line
#one# should match O!N!E for instance




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

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 680
**************************************


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