[29428] in Perl-Users-Digest
Perl-Users Digest, Issue: 672 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 22 21:09:52 2007
Date: Sun, 22 Jul 2007 18:09:08 -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 Sun, 22 Jul 2007 Volume: 11 Number: 672
Today's topics:
Re: @arts <zaxfuuq@invalid.net>
Re: @arts <bik.mido@tiscalinet.it>
Re: @arts <bik.mido@tiscalinet.it>
Re: @arts <bik.mido@tiscalinet.it>
Re: @arts <wyzelli@yahoo.com>
Re: @arts <zaxfuuq@invalid.net>
Difference between two values in a column in Perl <venkateshwar@hotmail.com>
Re: Difference between two values in a column in Perl <m@rtij.nl.invlalid>
Re: Difference between two values in a column in Perl <wahab-mail@gmx.de>
funky TCP problems <cdalten@gmail.com>
Re: funky TCP problems <spamtrap@dot-app.org>
Re: In deep complex XML <sow@sow.org.pl>
Re: In deep complex XML <sow@sow.org.pl>
Re: In deep complex XML <paduille.4061.mumia.w+nospam@earthlink.net>
Re: mysql DB specific primary key xhoster@gmail.com
regexp as function? <stoupa@practisoft.cz>
Re: regexp as function? <noreply@gunnar.cc>
Re: wors on active perl but not on unix <nospam@home.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 22 Jul 2007 16:47:03 -0700
From: "Wade Ward" <zaxfuuq@invalid.net>
Subject: Re: @arts
Message-Id: <HcadnU2zNqzFXz7bnZ2dnUVZ_tGonZ2d@comcast.com>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:91b7a397f1pgb967hbcmpnhe8p186qp1gc@4ax.com...
> On Sun, 22 Jul 2007 13:08:54 -0700, "Wade Ward" <zaxfuuq@invalid.net>
> wrote:
> If it were a variable exported by a module, then it wouldn't have been
> a (Perl) special variable.
>
> perldoc Exporter
> perldoc perlvar
I looked through these. Exporter is simply over my head right now. perlvar
shows special functions beginning with @ as arrays.
>>2) I didn't see anything that looked like a declaration to me.
>>Apparently,
>>this is the declaration:
>>my ($since, @arts)=time-10*60*60;
>>RHS looks like a scalar. Before I modified the 24*60*60 to a smaller
>>number
>
> LHS is a list, thus RHS is a list, comprising one element, that gets
> assigned to $since, @arts remains as empty as if it had been declared
> like
>
> my @arts;
>
>>so as not to have 40k of output, it looked like time-24*60*60 would be a
>>biggish integer. I was thinking that this got assigned to $since, and
>>that
>
> Given the well known return value of time(), which you must have
> *surely* looked up in
>
> perldoc -f time
>
> it is obvious that the value you're dealing with is a "biggish
> integer."
Now, indeed, I have looked at that, but my reason for thinking that
time-24*60*60 was going to be a biggish integer was that with the
difference, it didn't look like there was a difference in type and 24*60*60
is manifestly an integer. To firm up the notion, I wrote this little
script:
#!/usr/bin/perl
use strict;
use warnings;
my $var=time();
print "Time is ", $var,"\n";
__END__
which gives: Time is 1185146611 .
Why didn't this work until I put 'my' in front of $var ?
> one to make this mistake, that I know. And I'm even more surprised
> that you didn't misinterpret in the same way another similar
> assignment:
>
> my (undef, $first, $last, undef)=$nntp->group($grp)
That one didn't throw me so much, because I've read cpan's net::nntp
serially and saw:
In an array context the return value is a list containing, the number of
articles in the group, the number of the first article, the number of the
last article and the group name.
It would seem that you didn't want the number of articles in the group or
the group name, and left it undef. Is undef a function in this usage?
$first and $last would be scalars that you used.
> None that I know. The closest one that springs to mind being
> <c>@ARGV</c>, but then the vast majority Perl special variables are
> punctuation ones, while the few remaining one are all uppercase, with
> the exception of $a and $b.
$a and $b have special meanings in sorting, according to perlvar.
Thanks for your help.
--
Wade Ward
------------------------------
Date: Sun, 22 Jul 2007 23:43:47 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: @arts
Message-Id: <vrj7a31ait5ao25o9bjnp5ehkj570h5m10@4ax.com>
On Sun, 22 Jul 2007 15:53:57 -0700, "Wade Ward" <zaxfuuq@invalid.net>
wrote:
>guess would follow. Perl certainly has a motley assortment of funky-looking
>variables, probably beginning with $_. A person can go cross-eyed looking
Don't imagine them to be more than they actually are.
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: Sun, 22 Jul 2007 23:47:41 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: @arts
Message-Id: <e2k7a3h6q9vfojrh37u451ub2m61999nqd@4ax.com>
On Sun, 22 Jul 2007 19:17:01 GMT, Tad McClellan <tadmc@seesig.invalid>
wrote:
>Here are all of Perl's special variables that begin with @
>that I can find:
>
> @LAST_MATCH_END
^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
> @+
> @LAST_MATCH_START
^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^
> @-
> @ARGV
> @F
> @INC
> @_
And those two are not Perl's but English.pm's.
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: Mon, 23 Jul 2007 00:05:49 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: @arts
Message-Id: <gvj7a3luqru6cab84jmvtel2rtkd37v2kd@4ax.com>
On Sun, 22 Jul 2007 16:47:03 -0700, "Wade Ward" <zaxfuuq@invalid.net>
wrote:
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>my $var=time();
>print "Time is ", $var,"\n";
>
> __END__
>which gives: Time is 1185146611 .
>Why didn't this work until I put 'my' in front of $var ?
Because that's why you're using strict at all: to restrict your
freedom in a way that will allow you to easily avoid some common
programming mistakes. *Of course* you have read
perldoc strict
haven't you?
>> my (undef, $first, $last, undef)=$nntp->group($grp)
[snip]
>It would seem that you didn't want the number of articles in the group or
>the group name, and left it undef. Is undef a function in this usage?
>$first and $last would be scalars that you used.
Yes, it is a function, and as with all functions, you can read about
it at
perldoc -f undef
undef in that usage is still a function, but you're only using its
return value, which is actually its most common use, at first sight.
>> None that I know. The closest one that springs to mind being
>> <c>@ARGV</c>, but then the vast majority Perl special variables are
>> punctuation ones, while the few remaining one are all uppercase, with
>> the exception of $a and $b.
>$a and $b have special meanings in sorting, according to perlvar.
Indeed.
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: Sun, 22 Jul 2007 22:53:15 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: @arts
Message-Id: <vdRoi.10614$4A1.8410@news-server.bigpond.net.au>
"Wade Ward" <zaxfuuq@invalid.net> wrote in message
news:_PudnYF7Q5eySj_bnZ2dnUVZ_rmjnZ2d@comcast.com...
> I'm picking apart the following script:
> #!/usr/bin/perl
You will almost certainly get a lot of benefit from this book...
http://slashdot.org/books/00/01/24/1156247.shtml
P
------------------------------
Date: Sun, 22 Jul 2007 20:35:23 -0700
From: "Wade Ward" <zaxfuuq@invalid.net>
Subject: Re: @arts
Message-Id: <0fidna3eWe9Gaj7bnZ2dnUVZ_gqdnZ2d@comcast.com>
"Peter Wyzl" <wyzelli@yahoo.com> wrote in message
news:vdRoi.10614$4A1.8410@news-server.bigpond.net.au...
> "Wade Ward" <zaxfuuq@invalid.net> wrote in message
> news:_PudnYF7Q5eySj_bnZ2dnUVZ_rmjnZ2d@comcast.com...
>> I'm picking apart the following script:
>> #!/usr/bin/perl
>
> You will almost certainly get a lot of benefit from this book...
>
> http://slashdot.org/books/00/01/24/1156247.shtml
That looks promising. If the knock on it is that it is too mathematical,
then that would likely be more of an attraction to me, as my bachelors was
in math. I just blew my book budget for the month on a fortran title, but I
could pick it up next month.
--
WW
------------------------------
Date: Sun, 22 Jul 2007 20:33:21 -0000
From: venkateshwar <venkateshwar@hotmail.com>
Subject: Difference between two values in a column in Perl
Message-Id: <1185136401.171847.86500@g12g2000prg.googlegroups.com>
Hi,
I have a large set of values like this in two different columns,both
the values are variables..
I need to check if first value(ValA) is same in any of the consecutive
values and then find the difference between valB of those two matched
valA! and the next instant the difference should be between the valB
of second one with third match.
For example in this set, 9 appears thrice. first time, the difference
shd be printed as 3099 - 3000, the next time, it should be printed as
5098 - 3099.
valA,valB
9,3000
10,3010
1,3011
2,1020
3,3001
4,4010
9,3099
5,4011
18,4020
19,2044
20,3098
9,5098
How do I do this in Perl??
regards
venkat.
------------------------------
Date: Sun, 22 Jul 2007 22:51:07 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Difference between two values in a column in Perl
Message-Id: <pan.2007.07.22.20.51.38@rtij.nl.invlalid>
On Sun, 22 Jul 2007 20:33:21 +0000, venkateshwar wrote:
> Hi,
>
> I have a large set of values like this in two different columns,both the
> values are variables..
>
> I need to check if first value(ValA) is same in any of the consecutive
> values and then find the difference between valB of those two matched
> valA! and the next instant the difference should be between the valB of
> second one with third match.
>
> For example in this set, 9 appears thrice. first time, the difference
> shd be printed as 3099 - 3000, the next time, it should be printed as
> 5098 - 3099.
>
> valA,valB
> 9,3000
> 10,3010
> 1,3011
> 2,1020
> 3,3001
> 4,4010
> 9,3099
> 5,4011
> 18,4020
> 19,2044
> 20,3098
> 9,5098
Put the values in an array of arrays, e.g.
my @vals=( [9,3000], [10, 3010] ... etc
(reading this in from a file is left as an exercise for the interested
reader)
Keep track of which values you have seen sofar.
my %seen;
Iterate over the array, skipping any values you have already seen.
for my $t (@vals) {
my ($valA, $valB) = @{$t};
last if %seen{$valA};
%seen{$valA}=1;
Find all entries that have the same valA.
my @allAs = grep { $_->[0] == $valA } @vals;
Iterate over this array.
my $last = shift @allAs;
while (defined(my $cur = shift @allAs)) {
print "$valA => $cur-$last\n";
$last = $cur;
}
}
All untested, full of syntax errors, possibly a few thinkos, but it
should get you started.
HTH,
M4
------------------------------
Date: Sun, 22 Jul 2007 23:06:13 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Difference between two values in a column in Perl
Message-Id: <f80ikl$1f0$1@mlucom4.urz.uni-halle.de>
venkateshwar wrote:
> For example in this set, 9 appears thrice. first time, the difference
> shd be printed as 3099 - 3000, the next time, it should be printed as
> 5098 - 3099.
>
> valA,valB
> 9,3000
> 10,3010
> 1,3011
> 2,1020
> 3,3001
> 4,4010
> 9,3099
> 5,4011
> 18,4020
> 19,2044
> 20,3098
> 9,5098
>
> How do I do this in Perl??
There are 100'es of possible solutions
in Perl, depending on the raw data
source, format, size etc.
One variant (data in a simple scalar)
would include:
...
# valA,valB
my $columns='
9,3000
10,3010
1,3011
2,1020
3,3001
4,4010
9,3099
5,4011
18,4020
19,2044
20,3098
9,5098
';
my %helper;
...
A 'helper' hash which elements contain
Arrays of the corresponding numbers,
lets put them in:
...
push @{ $helper{$1} }, $2
while $columns=~/\D*(\d+)\D*(\d+)/g;
...
Now, the keys of the hash %helper are
the 'first column', the values did
accumulate the second column on the
right place.
Now we can go through the hash and
find the differences:
...
map {
my $last = 0;
print "\n$_ ==> ";
for my $el ( @{$helper{$_}} ) {
print "$el - $last, ";
$last = $el
}
}
grep @{$helper{$_}} > 1,
keys %helper;
...
This must be read 'upwards', starts with
extracting the keys (first column), filtering
out those keys, which don't have more than
one value entry (the 'grep' line), the
remaining (one (9) in your case is brought
into the map {} block. There, the array
of values of the {9}-key is simply
looped through in order to see what it
contains (and printed).
This is intended as a 'building block'
only, (although it does work with your data),
the map should return an array of the
differences you need in each pass.
Regards
M.
------------------------------
Date: Sun, 22 Jul 2007 16:07:04 -0700
From: grocery_stocker <cdalten@gmail.com>
Subject: funky TCP problems
Message-Id: <1185145624.206414.244940@d30g2000prg.googlegroups.com>
Given the following
#!/usr/bin/perl -w
use IO::Socket;
my($handle, $line, $kidpid);
$handle =3D IO::Socket::INET->new(
PeerAddr =3D>"137.104.128.2",
PeerPort =3D>"23",
Proto=3D>"tcp",
)
or die "cant connect to port: $!";
$handle->autoflush(1);
print STDERR "[Connected]\n";
die "can't fork: $!" unless defined($kidpid =3D fork());
if($kidpid) {
while(defined($line =3D <$handle>)){
print STDOUT $line;
}
kill("TERM", $kidpid);
}
else {
while(defined ($line =3D <STDIN>)){
print $handle $line;
}
}
When I run it, I get
[cdalten@localhost]$ ./foo.pl
[Connected]
now, when I hit the 'enter' key on my keyboard, I get
?????
University of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
Then after a few seconds, I get
Username:
Error reading command input
However, what I really want to see is
Trying 137.104.128.2...
Connected to uwplatt.edu (137.104.128.2).
Escape character is '^]'.
University of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
Username:
What's my error in logic?
------------------------------
Date: Sun, 22 Jul 2007 19:55:32 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: funky TCP problems
Message-Id: <m2hcnwat8r.fsf@dot-app.org>
grocery_stocker <cdalten@gmail.com> writes:
> now, when I hit the 'enter' key on my keyboard, I get
> ?????
>
>
> University of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
>
> Then after a few seconds, I get
> Username:
> Error reading command input
>
>
> However, what I really want to see is
> Trying 137.104.128.2...
> Connected to uwplatt.edu (137.104.128.2).
> Escape character is '^]'.
>
>
>
> University of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
>
> Username:
>
>
>
> What's my error in logic?
You're simply connecting to a socket and printing what you get back.
The problem is that terminal emulation is not that simple; there are
also control sequences that your app must act upon instead of simply
printing them.
You might want to have a look at the Term::VT102 module on CPAN.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Sun, 22 Jul 2007 13:29:47 -0700
From: sow <sow@sow.org.pl>
Subject: Re: In deep complex XML
Message-Id: <1185136187.567351.163560@57g2000hsv.googlegroups.com>
On 22 Lip, 21:08, Eric Amick <eric-am...@comcast.net> wrote:
> On Sun, 22 Jul 2007 08:41:51 -0700, sow <s...@sow.org.pl> wrote:
> >I have problem with get specific values from xml script below:
>
> >$VAR1 = {
> > 'report_params' => {
> > 'customer_code' => 'name',
> > 'customer_id' => '123',
> > 'account_details' => [
> > {
> > 'account_code' => 'account01',
> > 'state_code' => 'DELETED',
> > 'related_ani' => {
> > 'state_code' => 'DELETED',
> > 'phone_number' => '123456',
> > 'object_id' => '12',
> > 'subscription' => [
> > {
> > 'valid_to' => '2007-07-17T13:42:46',
> > 'valid_from' => '2007-07-16T19:17:05',
> > 'service_type_code' => 'VoIP',
> > 'service_code' => 'serv01'
> > },
> > {
> > 'valid_to' => '2007-07-18T12:15:16',
> > 'session' => [
> > {
> > 'currency_code' => 'QWE',
> > 'duration' => '0',
> > 'amount' => '0',
> > },
> > {
> > 'currency_code' => 'QWE',
> > 'duration' => '1313',
> > 'amount' => '-1.75',
> > }
> > ],
> > 'valid_from' => '2007-07-17T13:43:23',
> > 'service_type_code' => 'VoIP',
> > 'service_code' => 'serv02'
> > },
> > {
> > 'valid_to' => '2007-07-18T12:51:19',
> > 'valid_from' => '2007-07-18T12:47:51',
> > 'service_type_code' => 'VoIP',
> > 'service_code' => 'serv03'
> > }
> > ]
> > },
> > 'created_date' => '2007-07-16T19:02:12'
> > },
> > {
> > 'account_code' => 'account02',
> > 'state_code' => 'ENABLED',
> > 'related_ani' => {
> > 'state_code' => 'ENABLED',
> > 'phone_number' => '123456',
> > 'object_id' => '13',
> > 'subscription' => [
> > {
> > 'session' => [
> > {
> > 'currency_code' => 'QWE',
> > 'duration' => '0',
> > 'amount' => '0',
> > },
> > {
> > 'currency_code' => 'QWE',
> > 'duration' => '150',
> > 'amount' => '-1.975',
> > },
> > {
> > 'currency_code' => 'SEC',
> > 'duration' => '101',
> > 'amount' => '-101',
> > },
> > {
> > 'currency_code' => 'SEC',
> > 'duration' => '616',
> > 'amount' => '-616',
> > }
> > ],
> > 'valid_from' => '2007-07-18T12:56:33',
> > 'service_type_code' => 'VoIP',
> > 'service_code' => 'serv04'
> > }
> > },
> > 'created_date' => '2007-07-18T12:52:47'
> > }
> > ],
> > };
>
> >and script in perl:
>
> >#!/usr/bin/perl
> >use XML::Simple;
> >$xml = new XML::Simple;
> >$data = $xml->XMLin($ARGV[0],
> >KeyAttr => {account_details => 'account_code',subscription =>
> > 'service_code',session => 'currency_code'},
> >ForceArray => 1,
> >);
>
> >foreach $e (@{$data->{account_details}->{account02}->
> > {related_ani}->{subscription}->{serv04}->{session}->{QWE}})
> >{
> >printf "value %20s\n",$e->{amount};
> >}
>
> >and I've error:
> >Pseudo-hashes are deprecated at ./script line 9.
> >No such pseudo-hash field "account02" at ./billing2 line 9.
>
> >Any advice?
>
> Dump the structure of $data after you construct it; I think you'll find
> account02 is not a hash reference.
> --
> Eric Amick
> Columbia, MD
so how can I change it
------------------------------
Date: Sun, 22 Jul 2007 13:55:47 -0700
From: sow <sow@sow.org.pl>
Subject: Re: In deep complex XML
Message-Id: <1185137747.717582.47560@d55g2000hsg.googlegroups.com>
And if I change
ForceArray => 1 to
ForceArray => ['account_details','subscription','session']
I get:
Not an ARRAY reference at ./billing2 line 9
mabye is the other way how to get this values "amount" from xml using
XML::Simle
------------------------------
Date: Sun, 22 Jul 2007 21:39:20 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: In deep complex XML
Message-Id: <c8Qoi.9910$tj6.4990@newsread4.news.pas.earthlink.net>
On 07/22/2007 10:41 AM, sow wrote:
> I have problem with get specific values from xml script below:
>
> $VAR1 = {
> 'report_params' => {
> 'customer_code' => 'name',
> 'customer_id' => '123',
> 'account_details' => [...]
The data you posted does not compile for me. There is a missing bracket
or brace somewhere.
------------------------------
Date: 22 Jul 2007 21:03:35 GMT
From: xhoster@gmail.com
Subject: Re: mysql DB specific primary key
Message-Id: <20070722170338.392$gi@newsreader.com>
pistachio <hpbenton@gmail.com> wrote:
> > You could have posted this question anywhere that MySQL is on topic.
> Yes I guess I could but I was looking for Perl help :D
>
> > If the primary key is flagged as "auto-increment" then the whole basis
> > for your script has vanished. In that case the value of the primary key
> > is meaningless to all except for the MySQL server itself. Even though
> > you can query for it and see gaps in its value, your obsession to fill
> > those gaps is at best not recommended and at worst a mild case of OCD.
> Actually it's not. The database is an online DB
As opposed to a DB that is encased in concrete and buried in a unused
coal mine?
> where the primary key
> is used as a ref to the data. Hence I cannot reset it as you suggest,
He didn't suggest you reset it.
> nor is it an OCD type thing. I have a prim key of 15000 odd ppl think
> there are 15000 piece's of info in the db, which isn't true.
Odd people are going to think odd things, no matter what you do.
Micromanaging your database in an attempt to cure other people's delusions
is a losing proposition.
> Before
> you go and tell me that wasn't the way to make the DB, I wasn't the
> one to make it, I'm just responsible for it.
No, you seem to be determined to compound the original mistakes over
and over again. That makes you irresponsible for it.
> >
> > use DBI;
> Umm funny. I was thinking more like the DBI select command with the
> perl capture,
How could we do that without first have the DBI loaded? Since you
already seem to know what it is you want, what exactly are you asking
us for? How about you show us what you already have and tell us
where you got stuck?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 23 Jul 2007 02:14:39 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: regexp as function?
Message-Id: <f80rtl$28vq$1@ns.felk.cvut.cz>
I have variable $a and want to put into variable $b value of $a but modified
by regexp and not need to modify value of $a.
Beginner's way:
use strict;
my $a = '10,12,2007';
my $b = $a;
$b =~ s/,/./g;
print $b;
# result is 10.12.2007
I thinked up other two ways how to do the same but maybe is here more ways
which I don't know ;-)
# way 1
use strict;
my $a = '10,12,2007';
my $b = $_, s/,/./g, $a;
print $b;
# way 2
use strict;
my $a = '10,12,2007';
my $b;
($b = $a) =~ s/,/./g;
print $b;
I want to know how to write regexp as "function" as this is possible in PHP
where I can to write
my $a = '10,12,2007';
$b = preg_replace( 's/,/./' , $a);
Any ideas or comments are welcomed ;-)
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Mon, 23 Jul 2007 02:58:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regexp as function?
Message-Id: <5gicv7F3fqg3rU1@mid.individual.net>
Petr Vileta wrote:
> I have variable $a and want to put into variable $b value of $a but
> modified by regexp and not need to modify value of $a.
I think this is what you are looking for:
($b = $a) =~ s/,/./g;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 22 Jul 2007 23:17:04 GMT
From: "Nospam" <nospam@home.com>
Subject: Re: wors on active perl but not on unix
Message-Id: <QzRoi.652$mZ5.474@newsfe6-win.ntli.net>
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use WWW::Mechanize;
my $total_count = 0;
my @keywords = ('simpsons',
'diehard',
'fantastic+four',
);
foreach my $keywords(@keywords){
my $url
='http://news.google.co.uk/search?q=~%22'.$keywords.'&num=100&hl=en&safe=off
&start=0&as_qdr=all&filter=0';
my $mech = WWW::Mechanize->new();
$mech->get($url);
print $mech->uri."\n";
my @links_to_check = grep { $_->url() !~ /google/i}
$mech->find_all_links( url_regex => qr/\./i );
foreach my $links_to_check (@links_to_check)
{
$total_count++;
print "$links_to_check \n";
}
}
print " $total_count news items found \n";
On activeperl I get approx 894 results, while on a server, I get 0 results
------------------------------
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 672
**************************************