[28062] in Perl-Users-Digest
Perl-Users Digest, Issue: 9426 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 5 09:05:52 2006
Date: Wed, 5 Jul 2006 06:05:05 -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, 5 Jul 2006 Volume: 10 Number: 9426
Today's topics:
date format <silvan.spross@gmail.com>
Re: date format <josef.moellers@fujitsu-siemens.com>
Re: date format <bart@nijlen.com>
Re: date format <someone@example.com>
Re: date format <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: date format <scobloke2@infotop.co.uk>
Re: date format anno4000@radom.zrz.tu-berlin.de
Re: date format <bart@nijlen.com>
Re: date format <tadmc@augustmail.com>
How to use mechanize on https pages? <info@perot.com>
Re: How to use mechanize on https pages? <no@email.com>
Re: How to use mechanize on https pages? <manojkumargupta@gmail.com>
Re: Learning Typeglobs, Symbol Tables and the More Obsc anno4000@radom.zrz.tu-berlin.de
Re: Problem with split <scobloke2@infotop.co.uk>
Re: Problem with split anno4000@radom.zrz.tu-berlin.de
Re: Problem with split <someone@example.com>
Re: Problem with split <rvtol+news@isolution.nl>
Re: ReadKey/ ReadLine query anno4000@radom.zrz.tu-berlin.de
Re: Searching a string in a list of delimited fields <ronaldf@eml.cc>
unicode nicolas_laurent545@hotmail.com
Re: unicode <witek@ftw.at>
Re: unicode <rvtol+news@isolution.nl>
Re: unicode nicolas_laurent545@hotmail.com
Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade ben.wilder@gmail.com
Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrad anno4000@radom.zrz.tu-berlin.de
Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrad ben.wilder@gmail.com
Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrad anno4000@radom.zrz.tu-berlin.de
Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrad ben.wilder@gmail.com
Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrad <rvtol+news@isolution.nl>
Re: Using reference for performance gain? anno4000@radom.zrz.tu-berlin.de
Re: Using reference for performance gain? <howachen@gmail.com>
Re: Win32: File Manipulation <jue@monster-berlin.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 5 Jul 2006 00:08:56 -0700
From: "spross" <silvan.spross@gmail.com>
Subject: date format
Message-Id: <1152083336.059286.280360@m79g2000cwm.googlegroups.com>
hi
sorry, i'm a beginner :)
i have a file and the first line looks like:
%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
my question: how chan i get the date in this header in a format like:
YYYYMMDD
thanks for help!
spross
------------------------------
Date: Wed, 05 Jul 2006 09:24:52 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: date format
Message-Id: <e8fpk6$5kp$1@nntp.fujitsu-siemens.com>
spross wrote:
> hi
>=20
> sorry, i'm a beginner :)
> i have a file and the first line looks like:
>=20
> %%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
>=20
> my question: how chan i get the date in this header in a format like:
> YYYYMMDD
What have you tried so far and where did it fail?
Please post the code that you think should do the work and we'll comment =
and help.
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 5 Jul 2006 01:03:18 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: date format
Message-Id: <1152086598.473999.113920@a14g2000cwb.googlegroups.com>
spross wrote:
> sorry, i'm a beginner :)
> i have a file and the first line looks like:
>
> %%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
>
> my question: how chan i get the date in this header in a format like:
> YYYYMMDD
#!perl
use strict;
use warnings;
my $file =
'%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
1111111111111111111111
2222222222222222222222
3333333333333333333333
';
my @m = ('Jan', 'Feb', 'Mar', 'Apr', 'May',
'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
my @ar = split / /, (split /\n/, $file)[0];
$ar[3] =~ s/$m[$_]/@{[sprintf('%02g',$_+1)]}/ for (0..$#m);
die "Can't find month '$ar[3]'\n" unless $ar[3]=~/^(0|1)[0-9]$/;
print $ar[7], $ar[3], sprintf('%02g',$ar[4]);
__END__
Hope this helps,
--
Bart
------------------------------
Date: Wed, 05 Jul 2006 09:13:48 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: date format
Message-Id: <gpLqg.118925$S61.10409@edtnps90>
spross wrote:
>
> sorry, i'm a beginner :)
> i have a file and the first line looks like:
>
> %%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
>
> my question: how chan i get the date in this header in a format like:
> YYYYMMDD
$ perl -le'
$_ = q[%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%];
print;
my %mons = qw/
Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6
Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12
/;
/ \s
(?: Mon | Tue | Wed | Thu | Fri | Sat | Sun )
\s+
( @{[ join q[|], keys %mons ]} )
\s+
( \d\d? )
\s+
\d{2} : \d{2} : \d{2}
\s+
\S+
\s+
( \d{4} )
\s
/x && ( $_ = sprintf q[%04d%02d%02d], $3, $mons{ $1 }, $2 );
print;
'
%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
20060616
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 05 Jul 2006 09:29:06 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: date format
Message-Id: <CDLqg.3460$ye3.2189@newsread1.news.pas.earthlink.net>
spross wrote:
> hi
>
> sorry, i'm a beginner :)
> i have a file and the first line looks like:
>
> %%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
>
> my question: how chan i get the date in this header in a format like:
> YYYYMMDD
>
> thanks for help!
> spross
>
Use Date::Parse and Date::Format:
use Date::Parse qw(str2time);
use Date::Format qw(time2str);
local $_ = q{
%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
};
if (m/HEADER ([^%]+)/) {
my $time = str2time($1);
print "\$time = $time\n";
print time2str("%Y%m%d", $time);
}
HTH
------------------------------
Date: Wed, 05 Jul 2006 10:51:53 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: date format
Message-Id: <cfadnedfufBcFjbZnZ2dnUVZ8qudnZ2d@bt.com>
Bart Van der Donck wrote:
> spross wrote:
>
>
>>sorry, i'm a beginner :)
>>i have a file and the first line looks like:
>>
>>%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
>>
>>my question: how chan i get the date in this header in a format like:
>>YYYYMMDD
>
>
> #!perl
> use strict;
> use warnings;
> my $file =
> '%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
> 1111111111111111111111
> 2222222222222222222222
> 3333333333333333333333
> ';
> my @m = ('Jan', 'Feb', 'Mar', 'Apr', 'May',
> 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
> my @ar = split / /, (split /\n/, $file)[0];
> $ar[3] =~ s/$m[$_]/@{[sprintf('%02g',$_+1)]}/ for (0..$#m);
> die "Can't find month '$ar[3]'\n" unless $ar[3]=~/^(0|1)[0-9]$/;
> print $ar[7], $ar[3], sprintf('%02g',$ar[4]);
>
> __END__
>
> Hope this helps,
>
I'm not a beginner and I found this example rather obscure and hard to
understand. Perl needn't look that much like line noise IMO.
I'd put the data in a DATA section since it gives a structure
'while(<>){}' that is closer to the way most peaple read data files.
I'd use meaningful variable names since the OP claims to be a beginner
(though I think they're a good idea no matter your level of experience)
Here's how I would do it ...
#!/usr/bin/perl
use strict;
use warnings;
my $i = 1;
my %monthno = map {$_, $i++}
qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
while(<DATA>) {
if (/HEADER \w+ (\w+) (\d+) \d+:\d+:\d+ \w+ (\d+)/) {
die "unknown month name $1" unless $monthno{$1};
printf ("%4d%.2d%2d\n", $3, $monthno{$1}, $2);
}
}
__DATA__
%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
1111111111111111111111
2222222222222222222222
3333333333333333333333
%%%%%%%% HEADER Fri Foo 16 17:21:03 MEST 2006 %%%%%%%%%%%%
Doubtless it can be improved in many ways (and I, for one, would be
interested to see how). I nearly named $i as $index but for me the
purpose and content of $i is clear enough.
------------------------------
Date: 5 Jul 2006 10:32:09 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: date format
Message-Id: <4h1ip9F1ot820U1@news.dfncis.de>
Ian Wilson <scobloke2@infotop.co.uk> wrote in comp.lang.perl.misc:
> Bart Van der Donck wrote:
> > spross wrote:
[previous solution snipped]
> I'm not a beginner and I found this example rather obscure and hard to
> understand. Perl needn't look that much like line noise IMO.
>
> I'd put the data in a DATA section since it gives a structure
> 'while(<>){}' that is closer to the way most peaple read data files.
>
> I'd use meaningful variable names since the OP claims to be a beginner
> (though I think they're a good idea no matter your level of experience)
>
> Here's how I would do it ...
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> my $i = 1;
> my %monthno = map {$_, $i++}
> qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> while(<DATA>) {
> if (/HEADER \w+ (\w+) (\d+) \d+:\d+:\d+ \w+ (\d+)/) {
> die "unknown month name $1" unless $monthno{$1};
> printf ("%4d%.2d%2d\n", $3, $monthno{$1}, $2);
> }
> }
> __DATA__
> %%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%
> 1111111111111111111111
> 2222222222222222222222
> 3333333333333333333333
> %%%%%%%% HEADER Fri Foo 16 17:21:03 MEST 2006 %%%%%%%%%%%%
>
>
> Doubtless it can be improved in many ways (and I, for one, would be
> interested to see how). I nearly named $i as $index but for me the
> purpose and content of $i is clear enough.
In production code I would provide a smaller scope for $i. "do" blocks
can be handy for that (untested):
my %monthno = do {
my $i = 0;
map { $_ => ++ $i }
qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
};
Alternatively, one of the date/time modules from CPAN could be used.
I happen to have Date::Parse around.
use Date::Parse qw( strptime);
my $line = "%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006 %%%%%%%%%%%%";
my ($day,$month,$year) = (strptime( $line =~ /% HEADER (.*) %/))[ 3 .. 5];
printf "%4d%02d%02d\n", $year + 1900, $month + 1, $day;
Anno
------------------------------
Date: 5 Jul 2006 03:57:48 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: date format
Message-Id: <1152097067.988048.131040@p79g2000cwp.googlegroups.com>
Ian Wilson wrote:
> Bart Van der Donck wrote:
> > [...]
> > #!perl
> > use strict;
> > use warnings;
> > my $file =
> > '%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006
> > %%%%%%%%%%%%
> > 1111111111111111111111
> > 2222222222222222222222
> > 3333333333333333333333
> > ';
> > my @m = ('Jan', 'Feb', 'Mar', 'Apr', 'May',
> > 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
> > my @ar = split / /, (split /\n/, $file)[0];
> > $ar[3] =~ s/$m[$_]/@{[sprintf('%02g',$_+1)]}/ for (0..$#m);
> > die "Can't find month '$ar[3]'\n" unless $ar[3]=~/^(0|1)[0-9]$/;
> > print $ar[7], $ar[3], sprintf('%02g',$ar[4]);
> >
> > __END__
> >
> > Hope this helps,
>
> I'm not a beginner and I found this example rather obscure and hard to
> understand. Perl needn't look that much like line noise IMO.
I think you've entered the domain of personal preferences here. As far
as I'm concerned, my code doesn't read as line noise (I can easliy
follow it, but hey, that's me).
I for one have more difficulty to follow Mr Krahn's code, as I'm not
too confident with some of his techniques... But I do think that his
code will be perceived as more obscure by a beginner when you juxtapose
it next to mine.
But of course I do like occasional "sport lines" like
$ar[3] =~ s/$m[$_]/@{[sprintf('%02g',$_+1)]}/ for (0..$#m);
in stead of splitting it up in 5 lines or so, like I would rather do in
production code. Just do myself a favour in the future :-)
> I'd put the data in a DATA section since it gives a structure
> 'while(<>){}' that is closer to the way most peaple read data files.
I agree, that would have been better indeed.
> I'd use meaningful variable names since the OP claims to be a beginner
> (though I think they're a good idea no matter your level of experience)
$file = file
@ar short for array (which isn't descriptive for its content of course,
but the content of that array is not univocal here anyway)
@m short for @months
Well, yes, when written in full they would become more meaningful I
suppose...
> [...]
--
Bart
------------------------------
Date: Wed, 5 Jul 2006 07:26:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: date format
Message-Id: <slrneanbuv.c38.tadmc@magna.augustmail.com>
Bart Van der Donck <bart@nijlen.com> wrote:
> Ian Wilson wrote:
>> Bart Van der Donck wrote:
>> > my $file =
>> > '%%%%%%%% HEADER Fri Jun 16 17:21:03 MEST 2006
>> > %%%%%%%%%%%%
>> > 1111111111111111111111
>> > 2222222222222222222222
>> > 3333333333333333333333
>> > ';
>> I'd use meaningful variable names since the OP claims to be a beginner
>> (though I think they're a good idea no matter your level of experience)
>
> $file = file
$file = string !!
A meaningful name then might be:
my $file_contents =
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 5 Jul 2006 09:32:50 +0200
From: <info@perot.com>
Subject: How to use mechanize on https pages?
Message-Id: <e8fpuo$hrt$1@ss408.t-com.hr>
How to use mechanize on https pages?
Thanks
------------------------------
Date: Wed, 05 Jul 2006 09:04:09 +0100
From: Brian Wakem <no@email.com>
Subject: Re: How to use mechanize on https pages?
Message-Id: <4h1a3pF1p2sp5U1@individual.net>
info@perot.com wrote:
> How to use mechanize on https pages?
>
> Thanks
use Crypt::SSLeay;
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: 5 Jul 2006 01:10:24 -0700
From: "perlguru" <manojkumargupta@gmail.com>
Subject: Re: How to use mechanize on https pages?
Message-Id: <1152087024.658269.251130@m79g2000cwm.googlegroups.com>
You can check below link for details
http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize/FAQ.pod
And try using the module WWW::Mechanize :-
http://search.cpan.org/~petdance/WWW-Mechanize-1.18/lib/WWW/Mechanize.pm
.... Manoj Gupta
Brian Wakem wrote:
> info@perot.com wrote:
>
> > How to use mechanize on https pages?
> >
> > Thanks
>
>
> use Crypt::SSLeay;
>
>
> --
> Brian Wakem
> Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: 5 Jul 2006 09:58:40 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Learning Typeglobs, Symbol Tables and the More Obscure Features?
Message-Id: <4h1gqgF1p571hU1@news.dfncis.de>
Veli-Pekka Tätilä <vtatila@mail.student.oulu.fi> wrote in comp.lang.perl.misc:
> Hi,
> I'd like to learn more about the various ways to access and use type globs
> and how to deal with symbol table entries.
Don't sweat it. There is one thing a Perl programmer needs to know
about globs, and that is what
*glob = $ref;
does, where $ref is an arbitrary (non-symbolic) reference. You know
that, don't you? All everyday aliasing and symbol-table munging can
be done through that.
Everything else about globs and symbol tables is best looked up when
you need it and forgotten as soon as possible.
> Now that I'm here I'll also slip in another
> question, howabout docs on the rest of the more obscure features that make
> Perl perl such as formats and symbolic references under use strict 'vars'.
In my opinion, formats are strictly optional. Some people who happen
to know how to work with formats still use them, but the majority of
Perl programmers don't. There is nothing you can do with formats that
can't be achieved with normal IO and one or two modules like Text::Wrap,
and you don't have to concern yourself with yet another sub-language.
Symbolic references are syntactically no different from real refs. Just
use a string that contains the name of a package variable instead of
a real ref, and you'll access that. It's the semantics of symrefs that
makes them messy, since it blurs the distinction between data and
code.
> PS: Is it a type glob or a typeglob or are both forms OK?
From one second-language speaker of English to another: both are okay.
Anno
------------------------------
Date: Wed, 05 Jul 2006 10:09:56 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Problem with split
Message-Id: <fMydnX-r7eR0HDbZRVnysg@bt.com>
John W. Krahn wrote:
> A. Sinan Unur wrote:
>
>>"DJ Stunks" <DJStunks@gmail.com> wrote in
>>news:1152058999.182079.297620@l70g2000cwa.googlegroups.com:
>>
>>
>>>DJ Stunks wrote:
>>
>>...
>>
>>
>>>>Question - when he was splitting on /./ why did he get an empty list?
>>>>
>>>>Observe:
>>>> C:\>perl -Mstrict -we "print qq{[$_]} for split /./,'some.string'"
>>
>>Every character is a separator. Therefore, there are no fields.
>
>
> Actually there are a lot of fields, its just that empty trailing fields aren't
> returned from split unless you use a negative third argument:
Indeed, on my system, `perldoc -f split` says
split Splits a string into a list of strings and returns that list.
By default, empty leading fields are preserved, and empty
trailing ones are deleted.
It seems that when there are no non-empty fields, all the empty fields
are (arbitrarily?) deemed to be trailing ones, and are thus deleted from
the result.
>
> $ perl -le 'print map qq{[$_]}, split /./, q[some.string]'
>
> $ perl -le 'print map qq{[$_]}, split /./, q[some.string], -1'
> [][][][][][][][][][][][]
>
Empty "trailing" fields *can* be returned without using a negative third
argument. Perhaps the following were too obvious to be worth mentioning?
$ perl -le 'print map qq{[$_]}, split /./, q[some.string], 12'
[][][][][][][][][][][][]
$ perl -le 'print map qq{[$_]}, split /./, q[some.string], 99'
[][][][][][][][][][][][]
I can see the negative value is more generally useful, but I note that
it isn't the only value that can return empty "trailing" fields.
------------------------------
Date: 5 Jul 2006 09:25:11 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Problem with split
Message-Id: <4h1ernF1pb721U2@news.dfncis.de>
Ian Wilson <scobloke2@infotop.co.uk> wrote in comp.lang.perl.misc:
[snip]
> Indeed, on my system, `perldoc -f split` says
>
> split Splits a string into a list of strings and returns that list.
> By default, empty leading fields are preserved, and empty
> trailing ones are deleted.
>
> It seems that when there are no non-empty fields, all the empty fields
> are (arbitrarily?) deemed to be trailing ones, and are thus deleted from
> the result.
The documentation is a bit misleading in explicitly saying that "leading
empty fields are preserved". What actually happens is that trailing
empty fields are removed while leading ones are not treated specially
at all. When the leading empty fields also happen to be trailing ones,
as is the case here, all fields are removed.
Anno
------------------------------
Date: Wed, 05 Jul 2006 09:35:31 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Problem with split
Message-Id: <DJLqg.119071$S61.94950@edtnps90>
Ian Wilson wrote:
> John W. Krahn wrote:
>>
>> Actually there are a lot of fields, its just that empty trailing
>> fields aren't
>> returned from split unless you use a negative third argument:
>
> Indeed, on my system, `perldoc -f split` says
>
> split Splits a string into a list of strings and returns that list.
> By default, empty leading fields are preserved, and empty
> trailing ones are deleted.
>
> It seems that when there are no non-empty fields, all the empty fields
> are (arbitrarily?) deemed to be trailing ones, and are thus deleted from
> the result.
>
>> $ perl -le 'print map qq{[$_]}, split /./, q[some.string]'
>>
>> $ perl -le 'print map qq{[$_]}, split /./, q[some.string], -1'
>> [][][][][][][][][][][][]
>
> Empty "trailing" fields *can* be returned without using a negative third
> argument. Perhaps the following were too obvious to be worth mentioning?
>
> $ perl -le 'print map qq{[$_]}, split /./, q[some.string], 12'
> [][][][][][][][][][][][]
>
> $ perl -le 'print map qq{[$_]}, split /./, q[some.string], 99'
> [][][][][][][][][][][][]
>
> I can see the negative value is more generally useful, but I note that
> it isn't the only value that can return empty "trailing" fields.
The problem with using positive numbers is that you have to know beforehand
how much the regular expression will match and how long the string is. Using
a negative number will always return all empty trailing fields.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 5 Jul 2006 03:14:47 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Problem with split
Message-Id: <e8fb7k.188.1@news.isolution.nl>
Joe Smith schreef:
> DJ Stunks:
>> Question - when he was splitting on /./ why did he get an empty list?
>
> The first argument to split is what _not_ to return.
Unless capturing paren's are used, see perldoc -f split.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 5 Jul 2006 10:54:14 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: ReadKey/ ReadLine query
Message-Id: <4h1k2mF1ot820U3@news.dfncis.de>
V S Rawat <VSRawat@Invalid.none> wrote in comp.lang.perl.misc:
> V S Rawat wrote:
> > anno4000@zrz.tu-berlin.de wrote:
> > > V S Rawat <VSRawat@Invalid.none> wrote in comp.lang.perl.misc:
> >
> > > > 2. The following is not reaching "entered file name: " line, nor
> > > > is exiting at 0.
> > > > ----------------
> > > > use Term::ReadLine;
> > > > my $term = new Term::ReadLine 'Simple Perl calc';
> > > > my $prompt = "Input file name (0: Exit)? ";
> > > > my $OUT = $term->OUT || \*STDOUT;
> > > > while ( defined ($_ = $term->readline($prompt)) ) {
> > > > $InFile = eval($_);
> > > > warn $@ if $@;
> > > > print $OUT $InFile, "\n" unless $@;
> > > > $term->addhistory($_) if /\S/;
> > > > }
> > > >
> > > > if ($InFile == "0") {
> > > > exit;
> > > > }
> > > > print "entered file name: ", $InFile, "\n";
> > >
> > > Your while loop won't end except when you enter an EOF (^D under
> > > Unix). So the subsequent statements are never reached.
> > >
> > > Put the query for the loop end inside the loop.
> > >
> > > Anno
> >
> > Hmm! not becoming clear to me.
> >
> > Does the line "while ( defined ($_ = $term->readline($prompt)) ) {"
> > has some problem? I have copied it as such from the doc.
> >
> > file:///C:/Program%20Files/Perl/html/lib/Term/ReadLine.html
> > ---------------------start
> > SYNOPSIS
> >
> > use Term::ReadLine;
> > my $term = new Term::ReadLine 'Simple Perl calc';
> > my $prompt = "Enter your arithmetic expression: ";
> > my $OUT = $term->OUT || \*STDOUT;
> > while ( defined ($_ = $term->readline($prompt)) ) {
> > my $res = eval($_);
> > warn $@ if $@;
> > print $OUT $res, "\n" unless $@;
> > $term->addhistory($_) if /\S/;
> > }
> > ---------------------end
> >
> > or, is it general behaviour that a ReadLine terminates only with an
> > EOF, and not with a Enter key?
As the name implies, readline terminates when an end-of-line is
recognized. Pressing the Enter key does that. Then it returns
the line it has seen, which is *never* an undefined value. So
your loop goes on and on, never reaching the place where you ask
about the value of $InFile.
> > thanks.
>
> Adding:
>
> doc says:
> ------------start
> readline
>
> gets an input line, possibly with actual readline support. Trailing
> newline is removed. Returns undef on EOF.
> ----------end
>
> wouldn't that mean that EOF should not be used.
How do you deduce that? Entering EOF is the only way make readline()
return undef, and that is the only way to make your while-loop
terminate.
As noted, your must query the value of $InFile inside the loop, not
after it.
Anno
------------------------------
Date: Wed, 05 Jul 2006 10:52:19 +0200
From: Ronald Fischer <ronaldf@eml.cc>
Subject: Re: Searching a string in a list of delimited fields
Message-Id: <1152089539.69@user.newsoffice.de>
Mumia W. wrote as mumia.w.18.spam+nospam.usenet@earthlink.net on 04. Jul
2006:
> use Data::Dumper;
> use strict;
> my $s = "foo | bar baz | whoosh";
> my @fields = split /\s*\|\s*/, $s;
> my %fields;
> $fields{$fields[$_]} = $_ for (0..$#fields);
> print Dumper(\%fields), "\n";
Thank you very much to all of you for the suggestions.
Though using List::MoreUtils::first_index is the cleanest approach,
I will probably go either for the Data::Dumper way or Paul's
suggestion to program it in an explicit way, because List::MoreUtils,
according to the CPAN site, seems to be made for Perl 5.8.4 and beyond
(while my program needs also to run with 5.8.3).
Ronald
--
Ronald Fischer <ronaldf@eml.cc>
Posted via http://www.newsoffice.de/
------------------------------
Date: 5 Jul 2006 05:25:02 -0700
From: nicolas_laurent545@hotmail.com
Subject: unicode
Message-Id: <1152102302.919970.311410@75g2000cwc.googlegroups.com>
This command perl -pi -e 's/(\p{IsAplha}+)(=E9)(\s)/($1$2)/g' text.txt
returns
Can't find Unicode property definition "Aplha" at -e line 1, <> line 1.
What should I do to correct the problem ?
Thanks
------------------------------
Date: Wed, 05 Jul 2006 14:31:33 +0200
From: Tobias Witek <witek@ftw.at>
Subject: Re: unicode
Message-Id: <44abb209$0$12126$3b214f66@tunews.univie.ac.at>
nicolas_laurent545@hotmail.com wrote:
> This command perl -pi -e 's/(\p{IsAplha}+)(é)(\s)/($1$2)/g' text.txt
> returns
> Can't find Unicode property definition "Aplha" at -e line 1, <> line 1.
>
> What should I do to correct the problem ?
I guess you could probably try to spell "Alpha" correctly.
I am not an expert in Perl, but that might fix your problem :-D
------------------------------
Date: Wed, 5 Jul 2006 14:38:06 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: unicode
Message-Id: <e8gj90.q8.1@news.isolution.nl>
nicolas_laurent545 schreef:
> perl -pi -e 's/(\p{IsAplha}+)(é)(\s)/($1$2)/g' text.txt
> returns
> Can't find Unicode property definition "Aplha"
> at -e line 1, <> line 1.
>
> What should I do to correct the problem ?
See "perldoc perlre": IsAlpha
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 5 Jul 2006 05:57:52 -0700
From: nicolas_laurent545@hotmail.com
Subject: Re: unicode
Message-Id: <1152104272.447266.215620@j8g2000cwa.googlegroups.com>
Tobias Witek a =E9crit :
> nicolas_laurent545@hotmail.com wrote:
> > This command perl -pi -e 's/(\p{IsAplha}+)(=E9)(\s)/($1$2)/g' text.txt
> > returns
> > Can't find Unicode property definition "Aplha" at -e line 1, <> line 1.
> >
> > What should I do to correct the problem ?
>
> I guess you could probably try to spell "Alpha" correctly.
>
> I am not an expert in Perl, but that might fix your problem :-D
I am sorry but still have the problem with unicode.
perl -pi -e 's/(\p{IsAlpha}+)(=E9)(\s)/($1$2)/g' text.txt
This tell perl to take this as input
input:d=E9tr=F4n=E9 =F4pera=E9 =F4p=E9ra=E9 t=F4n=E2n=E9 t=FBt=E9=E9
expected output:(d=E9tr=F4n=E9) (=F4pera=E9) (=F4p=E9ra=E9) (t=F4n=E2n=E9)
(t=FBt=E9=E9)
actual output: d=E9tr=F4(n=E9)=F4(pera=E9)=F4p=E9(ra=E9)t=F4n=E2(n=E9)t=FBt=
=E9=E9
------------------------------
Date: 5 Jul 2006 02:49:10 -0700
From: ben.wilder@gmail.com
Subject: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade
Message-Id: <1152092950.363863.192910@b68g2000cwa.googlegroups.com>
Hi all,
Perl N00b here in need of a bit of kind assistance!
I am attempting to upgrade Perl from 5.8.6 to 5.8.8 on Fedora Core 4
I have performed the following:
Run: perl -V to get the version (5.8.6)
Downloaded perl version 5.8.8 and untarred
Run: ./Configure -des -Uusethreads
Run: make
Run: make test
Run: make install
All goes well - how do i alter my installation to now use this version
of perl, as running perl -V returns the same version information?
Many thanks for any help!
Ben
------------------------------
Date: 5 Jul 2006 10:07:11 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade
Message-Id: <4h1hafF1p571hU2@news.dfncis.de>
<ben.wilder@gmail.com> wrote in comp.lang.perl.misc:
> Hi all,
>
> Perl N00b here in need of a bit of kind assistance!
>
> I am attempting to upgrade Perl from 5.8.6 to 5.8.8 on Fedora Core 4
>
> I have performed the following:
>
> Run: perl -V to get the version (5.8.6)
> Downloaded perl version 5.8.8 and untarred
> Run: ./Configure -des -Uusethreads
> Run: make
> Run: make test
> Run: make install
>
> All goes well - how do i alter my installation to now use this version
> of perl, as running perl -V returns the same version information?
That should already have happened. Check your path. Normally (but not
always), the new version is installed as /usr/bin/perl. What does
"which perl" say?
Anno
------------------------------
Date: 5 Jul 2006 03:26:10 -0700
From: ben.wilder@gmail.com
Subject: Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade
Message-Id: <1152095170.687426.140860@a14g2000cwb.googlegroups.com>
Hi Anno,
Thanks for the reply,
the output to the statement "which perl" is as follows
/usr/local/bin/perl
interstingly enough, i have just reopened my SSH connection to perform
this command, and ran perl -v just to check and it appears the version
is now 5.8.8. However, this was DEFINATLEY not the case after i had run
make install, any ideas what could have caused that?
Thanks
Ben
------------------------------
Date: 5 Jul 2006 10:40:26 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade
Message-Id: <4h1j8qF1ot820U2@news.dfncis.de>
<ben.wilder@gmail.com> wrote in comp.lang.perl.misc:
> Hi Anno,
>
> Thanks for the reply,
What reply? I wrote seven or ten replies since yesterday -- which one
are you referring to? Please supply attributions and some context with
your reply.
> the output to the statement "which perl" is as follows
>
> /usr/local/bin/perl
Okay, that's not the standard location, though it's a close runner-up.
> interstingly enough, i have just reopened my SSH connection to perform
> this command, and ran perl -v just to check and it appears the version
> is now 5.8.8. However, this was DEFINATLEY not the case after i had run
> make install, any ideas what could have caused that?
That's a question about your system, not about Perl. Since you have told
us little about your system I can only guess. Perhaps you have a csh-like
shell that needs a "rehash" to honor changes in the actual environment.
Who knows.
Anno
------------------------------
Date: 5 Jul 2006 04:12:38 -0700
From: ben.wilder@gmail.com
Subject: Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade
Message-Id: <1152097958.198491.30960@l70g2000cwa.googlegroups.com>
Anno,
Thanks very much for you reply to my message dated Wed, Jul 5 2006
11:40 am Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade.
I'll investigate the issue regarding the version change of perl showing
5.8.6 even after the upgrade, your comments are much appreciated.
Answers much like i have come to expect from the open source community.
anno4000@radom.zrz.tu-berlin.de wrote:
> <ben.wilder@gmail.com> wrote in comp.lang.perl.misc:
> > Hi Anno,
> >
> > Thanks for the reply,
>
> What reply? I wrote seven or ten replies since yesterday -- which one
> are you referring to? Please supply attributions and some context with
> your reply.
>
> > the output to the statement "which perl" is as follows
> >
> > /usr/local/bin/perl
>
> Okay, that's not the standard location, though it's a close runner-up.
>
> > interstingly enough, i have just reopened my SSH connection to perform
> > this command, and ran perl -v just to check and it appears the version
> > is now 5.8.8. However, this was DEFINATLEY not the case after i had run
> > make install, any ideas what could have caused that?
>
> That's a question about your system, not about Perl. Since you have told
> us little about your system I can only guess. Perhaps you have a csh-like
> shell that needs a "rehash" to honor changes in the actual environment.
> Who knows.
>
> Anno
------------------------------
Date: Wed, 5 Jul 2006 13:19:04 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Upgrade perl from 5.8.6 to 5.8.8 - help with upgrade
Message-Id: <e8geb0.1dc.1@news.isolution.nl>
anno4000 schreef:
> ben.wilder:
>> the output to the statement "which perl" is as follows
>>
>> /usr/local/bin/perl
>
> Okay, that's not the standard location, though it's a close runner-up.
Big chance that /usr/bin/perl is a hardlink to /usr/local/bin/perl.
See "which -a perl" too.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 5 Jul 2006 09:05:46 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Using reference for performance gain?
Message-Id: <4h1dnaF1pb721U1@news.dfncis.de>
howa <howachen@gmail.com> wrote in comp.lang.perl.misc:
> hi,
>
> consider the following codes...
>
> it is interested that there is no performance gain when we use return
> by reference...or is that perl already optimized them for us?
For timing Perl code there is the standard module Benchmark.
> #--------------------------------------------------------------------
> sub test {
> my %h = (
> "a" => "asdsaefsayd7asdsdsdsdsdsdsatd7as6fdsa76smndfkjtpyty",
> "b" => "vdfdgdgregrehgregdsa6td76satd7as6fdsa76smndfdfdgfhf",
> "c" => "zxczxrhsadsadhsayd7asysgdsa6td76satd7as6fdsa76hthth",
> "d" => "jhthfgdsadsadhsayd7asysgdsa6td76satd7as6fdsahrhrhrh",
> "e" => "sfeghhfhsadsadhsayd7asysgdsa6td76satd7as6fdsahththt",
> "f" => "jgjgjgsadsadhsayd7asysgdsa6td76satd7as6fdseretttttg",
> "g" => "ekreorrsadsadhsayd7asysgdsa6td76satd7as6fdsadgdgggg",
> "h" => "sadsadhsayd7asysgdsa6td76satd7as6fdsa76smndfkjdfdfd",
> "i" => "mhjghhtsadsadhsayd7asysgdsa6td76satd7ahghghrrtrtrrt",
> "j" => "ewtyhrhsadsadhsayd7asysgdsa6td76satd7as6fdsa76smndf",
> "k" => "ykiyuiyutdhsayd7asysgdsa6td76satd7as6fdsa76smndfkjd"
> );
>
> # return %h;
> return \%h;
> }
>
> my $startTime = time();
>
> for ($count=1; $count<500000; $count++) {
> my $tmp = test();
> }
>
> my $endTime = time();
> print $endTime - $startTime;
Your benchmarks don't tell much about the actual performance of
returning a list vs. returning a reference. For one, you are building
the hash on each call to the routine. That is going to swamp out
other performance differences. Secondly, you are assigning the list
that is returned in one case to a scalar. That means that only one
scalar assignment is actually done, the others will be more or less
efficiently optimized away.
Here is a better benchmark:
use Benchmark qw( cmpthese);
my %h = (
"a" => "asdsaefsayd7asdsdsdsdsdsdsatd7as6fdsa76smndfkjtpyty",
"b" => "vdfdgdgregrehgregdsa6td76satd7as6fdsa76smndfdfdgfhf",
"c" => "zxczxrhsadsadhsayd7asysgdsa6td76satd7as6fdsa76hthth",
"d" => "jhthfgdsadsadhsayd7asysgdsa6td76satd7as6fdsahrhrhrh",
"e" => "sfeghhfhsadsadhsayd7asysgdsa6td76satd7as6fdsahththt",
"f" => "jgjgjgsadsadhsayd7asysgdsa6td76satd7as6fdseretttttg",
"g" => "ekreorrsadsadhsayd7asysgdsa6td76satd7as6fdsadgdgggg",
"h" => "sadsadhsayd7asysgdsa6td76satd7as6fdsa76smndfkjdfdfd",
"i" => "mhjghhtsadsadhsayd7asysgdsa6td76satd7ahghghrrtrtrrt",
"j" => "ewtyhrhsadsadhsayd7asysgdsa6td76satd7as6fdsa76smndf",
"k" => "ykiyuiyutdhsayd7asysgdsa6td76satd7as6fdsa76smndfkjd"
);
sub list { %h }
sub ref { \ %h }
cmpthese -1, {
list_ret => 'my %x = list()',
ref_ret => 'my $x = ref()',
};
...which prints
Rate list_ret ref_ret
list_ret 61837/s -- -98%
ref_ret 3633678/s 5776% --
In other words, in this case returning a reference is about 60 times
faster than returning the list.
Anno
------------------------------
Date: 5 Jul 2006 02:49:52 -0700
From: "howa" <howachen@gmail.com>
Subject: Re: Using reference for performance gain?
Message-Id: <1152092992.220889.281150@l70g2000cwa.googlegroups.com>
anno4000@radom.zrz.tu-berlin.de =E5=AF=AB=E9=81=93=EF=BC=9A
> Your benchmarks don't tell much about the actual performance of
> returning a list vs. returning a reference. For one, you are building
> the hash on each call to the routine. That is going to swamp out
> other performance differences.
i have considered this, but this just reflect the real world suitation.
Secondly, you are assigning the list
> that is returned in one case to a scalar. That means that only one
> scalar assignment is actually done, the others will be more or less
> efficiently optimized away.
yes, you are right.
thanks.
------------------------------
Date: 5 Jul 2006 05:27:10 -0700
From: "jue" <jue@monster-berlin.de>
Subject: Re: Win32: File Manipulation
Message-Id: <1152102430.567534.191280@v61g2000cwv.googlegroups.com>
Hello,
I am sorry but i think that you could not get an answer without a
full-functioning
sniped from your code.
ex.
What (type|module|.*) is $PickFTP?
(maybe this is selfexplained, but not for me... something like
Net::FTP?)
Where is the code which does the rename of your files local?
(so that they could be "put" remote)
There are some more questions which an executable extract form your
script
could answer.
It may help find your problem (by yourself... if not, post again) :)
Thomas
------------------------------
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 V10 Issue 9426
***************************************