[30329] in Perl-Users-Digest
Perl-Users Digest, Issue: 1572 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 23 14:09:43 2008
Date: Fri, 23 May 2008 11:09:09 -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 Fri, 23 May 2008 Volume: 11 Number: 1572
Today's topics:
Re: Auto-login to Facebook <fiacre.patrick@gmail.com>
Re: Auto-login to Facebook <cmic@caramail.com>
Re: Auto-login to Facebook <benkasminbullock@gmail.com>
Re: creating directory before a module is loaded. <pue@gmx.net>
Re: creating directory before a module is loaded. <jimsgibson@gmail.com>
Re: FAQ 4.59 How do I sort a hash (optionally by value <simon.chao@fmr.com>
Re: import CSV files to Excel <slick.users@gmail.com>
Re: import CSV files to Excel <1usa@llenroc.ude.invalid>
Re: import CSV files to Excel <jimsgibson@gmail.com>
Re: maintaining order in a hash (without Tie::IxHash) <rvtol+news@isolution.nl>
Re: maintaining order in a hash (without Tie::IxHash) <jurgenex@hotmail.com>
Re: Range of number <fiacre.patrick@gmail.com>
Re: Range of number <rvtol+news@isolution.nl>
Re: Range of number <szrRE@szromanMO.comVE>
reference/alias in perl vs reference/alias in C++ <cdalten@gmail.com>
Re: Strawberry windos xp problem <jurgenex@hotmail.com>
Re: Strawberry <ben@morrow.me.uk>
Re: Strawberry <jurgenex@hotmail.com>
TokeParser does not see javascript links ? <myicqKATTE@bakkegmx.net>
Re: TokeParser does not see javascript links ? <myicqKATTE@bakkegmx.net>
Using a buffer with HTTP::Response? <leifwessman@hotmail.com>
Re: Using a buffer with HTTP::Response? <bjoern@hoehrmann.de>
Re: using m//g to parse multi-line records without an o <astankevich@gmail.com>
Re: using m//g to parse multi-line records without an o <jimsgibson@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 23 May 2008 03:37:03 -0400
From: Andrew Lee <fiacre.patrick@gmail.com>
Subject: Re: Auto-login to Facebook
Message-Id: <4836741f$0$11616$607ed4bc@cv.net>
Ben Morrow wrote:
> Quoth FeelLikeANut@gmail.com:
>> Hi. I'm trying to write a script to automatically update some
>> information on Facebook. For now I'm just trying to get the login part
>> to work. Here's what I have:
>>
>> use LWP::UserAgent ();
>
> WWW::Mechanize is easier to work with for this sort of task. It handles
> all the nasty bits like cookies for you.
>
> Ben
>
perldoc WWW::Mechanize
.. Please note that Mech does NOT support JavaScript ...
I suspect Facebook runs on javascript ... just look at the source of the
page!
Also explains why it is laboriously slow.
------------------------------
Date: Fri, 23 May 2008 01:01:13 -0700 (PDT)
From: cmic <cmic@caramail.com>
Subject: Re: Auto-login to Facebook
Message-Id: <6e867790-5655-4493-a20f-cae42da69242@i76g2000hsf.googlegroups.com>
On 22 mai, 17:19, FeelLikeA...@gmail.com wrote:
> Hi. I'm trying to write a script to automatically update some
> information on Facebook. For now I'm just trying to get the login part
.... snip...
> getting and setting the cookies correctly, but I clearly must be doing
> something wrong. Can anybody help?
When I want to set up this kind of scripts, I first use a web scraping
proxy (written in Perl) which tell me everything about the infos
exchanged between the server and the navigator. Just ask Goooogle for
'web scraping proxy'. ATT or DrDobbs links should do.
Good luck.
--
michel marcon (aka cmic)
------------------------------
Date: Fri, 23 May 2008 10:35:47 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Auto-login to Facebook
Message-Id: <g166m3$5a5$1@ml.accsnet.ne.jp>
On Fri, 23 May 2008 03:37:03 -0400, Andrew Lee wrote:
> I suspect Facebook runs on javascript ... just look at the source of the
> page!
OK, I looked at it and www.facebook.com has lots of links to PHP scripts.
> Also explains why it is laboriously slow.
Um, yes, if they were running their web site inside a web browser it probably
would be very slow. But unless they're doing that, it's rather hard to think
how Facebook could be running on JavaScript.
------------------------------
Date: Fri, 23 May 2008 16:04:00 +0200
From: =?ISO-8859-1?Q?Andreas_P=FCrzer?= <pue@gmx.net>
Subject: Re: creating directory before a module is loaded.
Message-Id: <69o0sjF30rjvvU1@mid.individual.net>
gsa schrieb:
example.pm in turn uses
> the CPAN module Inline.pm.
Then you wrote:
> testInline.pl
> ---------------
> #!/usr/bin/perl -
> w
> use strict;
> use lib './libPvalueCalculation';
> use pvalueCalculation;
>
> BEGIN {
> my $return= `mkdir /tmp/RAP/test`;
> print "return: $return\n";
> }
>
> pvalueCalculation.pm
> ---------------------
> #!/usr/bin/perl -
> w
> use strict;
> use Inline (C => Config =>
> DIRECTORY => '/tmp/RAP/test',
> UNTAINT => '0',
> );
What happens if you put the BEGIN into pvalueCalculation.pm, where it is
actually needed?
Greetings,
Andreas Pürzer
--
Have Fun,
and if you can't have fun,
have someone else's fun.
The Beautiful South
------------------------------
Date: Fri, 23 May 2008 09:23:52 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: creating directory before a module is loaded.
Message-Id: <230520080923527051%jimsgibson@gmail.com>
In article <69o0sjF30rjvvU1@mid.individual.net>, Andreas Pürzer
<pue@gmx.net> wrote:
> gsa schrieb:
> example.pm in turn uses
> > the CPAN module Inline.pm.
>
>
> What happens if you put the BEGIN into pvalueCalculation.pm, where it is
> actually needed?
When the Perl interpreter encounters the first 'use pvalueCalculation;'
statement, it will find and process pvalueCalculation.pm. When it
encounters the BEGIN statement in that file, it will process and
execute its contents.
--
Jim Gibson
------------------------------
Date: Fri, 23 May 2008 06:30:50 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: FAQ 4.59 How do I sort a hash (optionally by value instead of key)?
Message-Id: <1dc5ae3f-58f8-4995-b508-ca0a237287a3@i76g2000hsf.googlegroups.com>
On May 23, 9:03=A0am, PerlFAQ Server <br...@stonehenge.com> wrote:
> This is an excerpt from the latest version perlfaq4.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is athttp://faq.perl.org.
>
> --------------------------------------------------------------------
>
> 4.59: How do I sort a hash (optionally by value instead of key)?
>
> =A0 =A0 (contributed by brian d foy)
>
> =A0 =A0 To sort a hash, start with the keys. In this example, we give the =
list
> =A0 =A0 of keys to the sort function which then compares them ASCIIbetical=
ly
> =A0 =A0 (which might be affected by your locale settings). The output list=
has
> =A0 =A0 the keys in ASCIIbetical order. Once we have the keys, we can go t=
hrough
> =A0 =A0 them to create a report which lists the keys in ASCIIbetical order=
.
>
> =A0 =A0 =A0 =A0 =A0 =A0 my @keys =3D sort { $a cmp $b } keys %hash;
>
> =A0 =A0 =A0 =A0 =A0 =A0 foreach my $key ( @keys )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf "%-20s %6d\n", $key, $hash{=
$key};
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> =A0 =A0 We could get more fancy in the "sort()" block though. Instead of
> =A0 =A0 comparing the keys, we can compute a value with them and use that =
value
> =A0 =A0 as the comparison.
>
> =A0 =A0 For instance, to make our report order case-insensitive, we use th=
e "\L"
> =A0 =A0 sequence in a double-quoted string to make everything lowercase. T=
he
> =A0 =A0 "sort()" block then compares the lowercased values to determine in=
which
> =A0 =A0 order to put the keys.
>
> =A0 =A0 =A0 =A0 =A0 =A0 my @keys =3D sort { "\L$a" cmp "\L$b" } keys %hash=
;
>
> =A0 =A0 Note: if the computation is expensive or the hash has many element=
s, you
> =A0 =A0 may want to look at the Schwartzian Transform to cache the computa=
tion
> =A0 =A0 results.
>
> =A0 =A0 If we want to sort by the hash value instead, we use the hash key =
to
> =A0 =A0 look it up. We still get out a list of keys, but this time they ar=
e
> =A0 =A0 ordered by their value.
>
> =A0 =A0 =A0 =A0 =A0 =A0 my @keys =3D sort { $hash{$a} <=3D> $hash{$b} } ke=
ys %hash;
>
> =A0 =A0 From there we can get more complex. If the hash values are the sam=
e, we
> =A0 =A0 can provide a secondary sort on the hash key.
>
> =A0 =A0 =A0 =A0 =A0 =A0 my @keys =3D sort {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $hash{$a} <=3D> $hash{$b}
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 or
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "\L$a" cmp "\L$b"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } keys %hash;
>
> --------------------------------------------------------------------
>
> The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
> are not necessarily experts in every domain where Perl might show up,
> so please include as much information as possible and relevant in any
> corrections. The perlfaq-workers also don't have access to every
> operating system or platform, so please include relevant details for
> corrections to examples that do not work on particular platforms.
> Working code is greatly appreciated.
>
> If you'd like to help maintain the perlfaq, see the details in
> perlfaq.pod.
really? is this some sort (har har) of perverse humor? or is there
some intelligence that does NLP on the posts to figure out which FAQ
to post? and no, i'm not paranoid--they really are out to get me.
------------------------------
Date: Fri, 23 May 2008 08:13:02 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: import CSV files to Excel
Message-Id: <f3335554-6d5b-4169-b48a-3e7e46502472@s50g2000hsb.googlegroups.com>
I think my Add function is not correct even though Perl doesn't
complain.
From OLE help:
Function Add(Connection, Destination As Range, [Sql]) As QueryTable
I try these two ways and it still don't import the data in.
$Excel->ActiveSheet->QueryTables->Add
> ({
> Connection=>$file,
> Destination=>$CurrentSheet->Range("A1")
> });
$Excel->ActiveSheet->QueryTables->Add
> ({
> $file,$CurrentSheet->Range("A1")
> });
On May 22, 10:12 am, Slickuser <slick.us...@gmail.com> wrote:
> I record a Macro.
>
> Here is what I got but my data is not import to A1.
>
> It did add the sheet in though. Any idea?
>
> Perl code:
>
> use strict;
> use warnings;
> use Win32::OLE;
> use Win32::OLE::Const 'Microsoft Excel';
> #use Win32::OLE::Variant;
>
> print localtime() ." START \n";
>
> my $localTime = localtime();
> $localTime =~ s/\s/_/g;
> $localTime =~ s/\:/_/g;
>
> my $csv_path = "C:/slickuser/Tue_May_20_20_49_44_2008/*.csv";
> my $fileOutput = "C:/slickuser/out.xls";
> my $MAX_ROW = 65356;
>
> my @csvFile = glob($csv_path);
> my ($Excel,$Workbook,$Workbook_CSV,$CurrentSheet);
>
> $Excel = Win32::OLE->new('Excel.Application', 'Quit') || die "Can't
> create Excel object \n";
> $Excel->{'Visible'} = 1; #0 is hidden, 1 is visible
> $Excel->{DisplayAlerts}= 0; #0 is hide alerts
> $Excel->{SheetsInNewWorkbook} = 0;
>
> $Workbook = $Excel->Workbooks->Add();
> $Workbook->SaveAs($fileOutput) or die "Can't save file.\n";
>
> foreach my $filename (sort(@csvFile))
> {
> $filename =~ s/\\/\//g;
> my @tempFile = split(/\//,$filename);
> my @sheetName = split(/\./,$tempFile[scalar(@tempFile)-1]);
>
> $Workbook->Worksheets->Add( {after => $Workbook->Worksheets($Workbook->Worksheets->{count})} );
>
> $CurrentSheet = $Workbook->ActiveSheet;
> $CurrentSheet->{Name} = $sheetName[0];
>
> my $column = "[";
> open(CSV,$filename) or die "Can't open CSV file.\n";
> while(<CSV>)
> {
> my $curLine = $_;
> my @cells = split(/\,/,$curLine);
>
> for (my $i=0; $i<(scalar @cells); $i++)
> {
> $column .= "1, ";
> }
> #Delete the last comma
> chop($column);
> $column .= "]";
>
> last;
> }
> close(CSV);
>
> my $file = "TEXT;$filename";
> $Excel->ActiveSheet->QueryTables->Add
> ({
> Connection=>$file,
> Destination=>$CurrentSheet->Range("A1")
> });
> $Excel->ActiveSheet->QueryTables->{Name} = $sheetName[0];
> $Excel->ActiveSheet->QueryTables->{FieldNames} = 1;
> $Excel->ActiveSheet->QueryTables->{RowNumbers} = 0;
> $Excel->ActiveSheet->QueryTables->{FillAdjacentFormulas}= 0;
> $Excel->ActiveSheet->QueryTables->{PreserveFormatting} = 1;
> $Excel->ActiveSheet->QueryTables->{RefreshOnFileOpen} = 0;
> $Excel->ActiveSheet->QueryTables->{BackgroundQuery} = 1;
> $Excel->ActiveSheet->QueryTables->{RefreshStyle} =
> xlInsertDeleteCells;
> $Excel->ActiveSheet->QueryTables->{SavePassword} = 0;
> $Excel->ActiveSheet->QueryTables->{SaveData} = 1;
> $Excel->ActiveSheet->QueryTables->{AdjustColumnWidth} = 1;
> $Excel->ActiveSheet->QueryTables->{RefreshPeriod}= 0;
> $Excel->ActiveSheet->QueryTables->{TextFilePromptOnRefresh} = 1;
> $Excel->ActiveSheet->QueryTables->{TextFilePlatform} = 437;
> $Excel->ActiveSheet->QueryTables->{TextFileStartRow} = 1;
> $Excel->ActiveSheet->QueryTables->{TextFileParseType} = xlDelimited;
> $Excel->ActiveSheet->QueryTables->{TextFileTextQualifier} =
> xlTextQualifierDoubleQuote;
> $Excel->ActiveSheet->QueryTables->{TextFileConsecutiveDelimiter} =
> 0;
> $Excel->ActiveSheet->QueryTables->{TextFileTabDelimiter} = 0;
> $Excel->ActiveSheet->QueryTables->{TextFileSemicolonDelimiter} = 0;
> $Excel->ActiveSheet->QueryTables->{TextFileCommaDelimiter} = 1;
> $Excel->ActiveSheet->QueryTables->{TextFileSpaceDelimiter} = 0;
> $Excel->ActiveSheet->QueryTables->{TextFileColumnDataTypes} =
> $column;
> $Excel->ActiveSheet->QueryTables->{TextFileTrailingMinusNumbers} =
> 1;
> $Workbook->Save();
> }
>
> $Workbook->Close();
> $Excel->Quit();
> Win32::OLE->FreeUnusedLibraries();
>
> print localtime() ." END \n";
>
> VBA code:
>
> Sheets.Add
> With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:/slickuser/
> 10.csv", _
> Destination:=Range("A1"))
> .Name = "10"
> .FieldNames = True
> .RowNumbers = False
> .FillAdjacentFormulas = False
> .PreserveFormatting = True
> .RefreshOnFileOpen = False
> .RefreshStyle = xlInsertDeleteCells
> .SavePassword = False
> .SaveData = True
> .AdjustColumnWidth = True
> .RefreshPeriod = 0
> .TextFilePromptOnRefresh = False
> .TextFilePlatform = 437
> .TextFileStartRow = 1
> .TextFileParseType = xlDelimited
> .TextFileTextQualifier = xlTextQualifierDoubleQuote
> .TextFileConsecutiveDelimiter = False
> .TextFileTabDelimiter = False
> .TextFileSemicolonDelimiter = False
> .TextFileCommaDelimiter = True
> .TextFileSpaceDelimiter = False
> .TextFileColumnDataTypes = Array(1, 1, 1, 1)
> .TextFileTrailingMinusNumbers = True
> .Refresh BackgroundQuery:=False
> End With
------------------------------
Date: Fri, 23 May 2008 15:40:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: import CSV files to Excel
Message-Id: <Xns9AA776D193416asu1cornelledu@127.0.0.1>
Slickuser <slick.users@gmail.com> wrote in
news:f3335554-6d5b-4169-b48a-3e7e46502472@s50g2000hsb.googlegroups.com:
> I think my Add function is not correct even though Perl doesn't
> complain.
>
> From OLE help:
> Function Add(Connection, Destination As Range, [Sql]) As QueryTable
>
> I try these two ways and it still don't import the data in.
I am going to suggest that you are being a little silly with the way you
are going about it. First of all, by importing the CSV first into Excel,
you are placing yourself at the mercy of Excel in terms of how cell
values should be treated.
Had I been in your position, I would have used Text::CSV_XS to parse the
CSV file line by line and add rows (and sheets as necessary) to an Excel
sheet using Spreadsheet::WriteExcel.
This has a few very important benefits: First, the memory footprint of
your application is minimized. Second, you decide whether the data you
read in is text or numbers or something else. Third, you can specify how
Excel should treat the values in cells.
For example, the online grading system we use at Cornell exports
gradebooks in CSV format. Students are identified by their so called Net
ID's which consist of two or three initials and 1-4 digits following
those initials. Now, if you are the 30th person at Cornell with the
initials mar, your Net ID would be mar30. Guess what Excel does to this
field if you double click on the filename to open it.
So, I would suggest you invest some intellectual capital in reading the
docs for Text::CSV_XS and Spreadsheet::WriteExcel. As a bonus, so long
as you are careful with file paths etc, your code will not need a
Windows machine with MS Office installed to run.
>> It did add the sheet in though. Any idea?
>> foreach my $filename (sort(@csvFile))
>> {
>> $filename =~ s/\\/\//g;
>> my @tempFile = split(/\//,$filename);
>> my @sheetName =
>> split(/\./,$tempFile[scalar(@tempFile)-1]);
See the methods provided by File::Spec. canonpath, splitpath, catfile
etc.
>> open(CSV,$filename) or die "Can't open CSV file.\n";
You should include the name of the file and the reason the file could
not be opened:
die "Can't open '$filename': $!";
>> while(<CSV>)
>> {
>> my $curLine = $_;
while ( my $curline = <CSV> ) {
>> my @cells = split(/\,/,$curLine);
Are you 100% absolutely double-sure that there are no embedded commas in
any cell?
use Text::CSV_XS;
>> for (my $i=0; $i<(scalar @cells); $i++)
$i < @cells is already evaluated in scalar context. There is no need for
scalar.
There is also no need for a zero based loop here.
>> {
>> $column .= "1, ";
>> }
>> #Delete the last comma
>> chop($column);
>> $column .= "]";
In fact, this whole loop should be submitted to thedailywtf.
As far as I can tell, what you are doing is equivalent to:
sprintf( '[ %s ]', join(',', (1) x @cells ) );
>> last;
>> }
>> close(CSV);
Why do you do this for every line in the CSV file? If this is a
rectangular data set, the number of columns does not change. If it is
jagged, what is the point of overwriting $column possibly thousands of
times
>> $Excel->ActiveSheet->QueryTables->{TextFileColumnDataTypes} =
>> $column;
to use it only once?
use Text::CSV_XS;
use Spreadsheet::WriteExcel;
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Fri, 23 May 2008 10:03:01 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: import CSV files to Excel
Message-Id: <230520081003017973%jimsgibson@gmail.com>
In article <Xns9AA776D193416asu1cornelledu@127.0.0.1>, A. Sinan Unur
<1usa@llenroc.ude.invalid> wrote:
> Slickuser <slick.users@gmail.com> wrote in
> news:f3335554-6d5b-4169-b48a-3e7e46502472@s50g2000hsb.googlegroups.com:
>
>
> As far as I can tell, what you are doing is equivalent to:
>
> sprintf( '[ %s ]', join(',', (1) x @cells ) );
>
> >> last;
> >> }
> >> close(CSV);
>
> Why do you do this for every line in the CSV file? If this is a
> rectangular data set, the number of columns does not change. If it is
> jagged, what is the point of overwriting $column possibly thousands of
> times
Thanks for responding to this post. I tried and failed to make sense of
it, too, and gave up. However, I think because of the 'last;' statement
in the loop, $column is only generated for the first line of each CSV
file.
>
> >> $Excel->ActiveSheet->QueryTables->{TextFileColumnDataTypes} =
> >> $column;
I scanned the code a couple of times and couldn't even find where
$column was used.
>
> to use it only once?
>
> use Text::CSV_XS;
> use Spreadsheet::WriteExcel;
My advice to the OP is the same as yours.
--
Jim Gibson
------------------------------
Date: Fri, 23 May 2008 10:35:32 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <g166pl.1n8.1@news.isolution.nl>
Jürgen Exner schreef:
> Which one is the next element after length('Hello')?
Well, length('World') of course.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Fri, 23 May 2008 12:32:58 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <6bed341jsf121l8e195d83c6664ou884dl@4ax.com>
"Dr.Ruud" <rvtol+news@isolution.nl> wrote:
>Jürgen Exner schreef:
>> Which one is the next element after length('Hello')?
>
>Well, length('World') of course.
:-))
jue
------------------------------
Date: Fri, 23 May 2008 03:23:47 -0400
From: Andrew Lee <fiacre.patrick@gmail.com>
Subject: Re: Range of number
Message-Id: <48367103$0$11638$607ed4bc@cv.net>
One wrote:
> Hi all -
>
> I have a pre-determined low number and a pre-determined high number.
> I simply need to know if my variable is within that range, and if so
> print YES
>
> I looked at Number::Range but thouhgt it was over kill.
>
> Should I use a regex ?
>
> Thx.
>
>
if ( $x < $hi and $x > $low ) {
print "YES\n";
}
Or am I not understanding your question?
------------------------------
Date: Fri, 23 May 2008 10:43:36 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Range of number
Message-Id: <g167cj.10k.1@news.isolution.nl>
Charlton Wilbur schreef:
> if ($number <= $MAXNUM && $number >= $MINNUM) .....
It must be my math education showing through, but I always write that in
order:
if ( $MINNUM <= $number and $number <= $MAXNUM )
to emphasize what is between what.
I might make an exception if I know beforehand that any of the criteria
occurs more often, to profit from the shortcutting.
In Perl6 you can write
if ( $MINNUM <= $number <= $MAXNUM )
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Fri, 23 May 2008 10:03:11 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Range of number
Message-Id: <g16tcg0pje@news4.newsguy.com>
Dr.Ruud wrote:
> Charlton Wilbur schreef:
>
>> if ($number <= $MAXNUM && $number >= $MINNUM) .....
>
> It must be my math education showing through, but I always write that
> in order:
>
> if ( $MINNUM <= $number and $number <= $MAXNUM )
>
> to emphasize what is between what.
> I might make an exception if I know beforehand that any of the
> criteria occurs more often, to profit from the shortcutting.
>
>
> In Perl6 you can write
>
> if ( $MINNUM <= $number <= $MAXNUM )
While I can see the convience in that, I can also see people slipping on
this, as most other languages (including Perl 5), would parse that by
first evaulating a boolean result from ($MINNUM <= $number) and then
(result <= $MAXNUM)... I don't know if any real code actually depends on
that behavior, but Perl 6 does seem to make that more useful.
Any word on such a construct making it's way into Perl 5 (5.12 perhaps?)
?
--
szr
------------------------------
Date: Fri, 23 May 2008 10:48:47 -0700 (PDT)
From: grocery_stocker <cdalten@gmail.com>
Subject: reference/alias in perl vs reference/alias in C++
Message-Id: <8f8a7081-f03a-4063-9999-36ba6dd1619f@u12g2000prd.googlegroups.com>
How are references and aliases in perl different than references in
aliases in C++?
------------------------------
Date: Fri, 23 May 2008 12:35:56 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Strawberry windos xp problem
Message-Id: <cfed34l62jn5rdid5l9gcsmlffqt2mqeod@4ax.com>
sanozuke <rahim.g.fakir@gmail.com> wrote:
>In the Command Prompt whern running:
>#! perl
>use Bit::Vector;
> $vec = Bit::Vector->new_Hex(32, "DEADBEEF");
> $dec = $vec->to_Dec();
>
>It shows a error
>
>Can't locate Bit/VEctor.pm in <@INC contains : C:/strawberry/perl C:/
>strawberry/perl*site/lib.> at exemplo13.pl line 2.
Most likely this has nothing to do with neither Strawberry nor XP. Did
you install Bit::Vector?
jue
------------------------------
Date: Fri, 23 May 2008 12:32:23 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Strawberry
Message-Id: <7jmig5-1v1.ln1@osiris.mauzo.dyndns.org>
Quoth sanozuke <rahim.g.fakir@gmail.com>:
> In the Command Prompt whern running:
> #! perl
> use Bit::Vector;
> $vec = Bit::Vector->new_Hex(32, "DEADBEEF");
> $dec = $vec->to_Dec();
>
> It shows a error
>
> Can't locate Bit/VEctor.pm in <@INC contains : C:/strawberry/perl C:/
> strawberry/perl*site/lib.> at exemplo13.pl line 2.
> Begin failed--compilation aborted at exemplo13.pl line 2.
You need to install Bit::Vector.
cpan -i Bit::Vector
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Fri, 23 May 2008 12:34:33 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Strawberry
Message-Id: <5eed34h7cr77505tnf052iqkreauufr0jr@4ax.com>
sanozuke <rahim.g.fakir@gmail.com> wrote:
>In the Command Prompt whern running:
>#! perl
>use Bit::Vector;
> $vec = Bit::Vector->new_Hex(32, "DEADBEEF");
> $dec = $vec->to_Dec();
>
>It shows a error
>
>Can't locate Bit/VEctor.pm in <@INC contains : C:/strawberry/perl C:/
>strawberry/perl*site/lib.> at exemplo13.pl line 2.
Did you install Bit::Vector?
jue
------------------------------
Date: 23 May 2008 08:52:58 GMT
From: T <myicqKATTE@bakkegmx.net>
Subject: TokeParser does not see javascript links ?
Message-Id: <Xns9AA76EBBC2E61myicqKATTEbakkegmxne@62.243.74.163>
I have a question reg. the Tokeparser. It does not seem to "find" links
(<a...> tags) that does not have a valid url.
In the URL below, there are links that look like
<a href="javascript:;" onclick="popupOTL(568,'{8C465561-A0CB-440B-A02E-
053329F76EB6}',0,880,676,false,'0');setWatched(this);">Long document
overview</a>
Yet, the TokeParser completely ignores that link. Why ?
Any help appreciated
Example:
#!/usr/bin/perl -w
use LWP::Simple;
use HTML::TokeParser;
my $cpanurl = 'http://movielibrary.lynda.com/html/modPage.asp?ID=568';
my $rawHTML = get($cpanurl); # attempt to d/l the page to mem
die "LWP::Simple messed up $!" unless ($rawHTML);
my $tp = HTML::TokeParser->new(\$rawHTML) || die "Can't open: $!";
while (my $token = $tp->get_tag("a"))
{
my $url = $token->[1]{href} || "-";
my $text = $tp->get_text("/a");
print "$url\t$text\n";
}
------------------------------
Date: 23 May 2008 09:18:07 GMT
From: T <myicqKATTE@bakkegmx.net>
Subject: Re: TokeParser does not see javascript links ?
Message-Id: <Xns9AA772F6F592DmyicqKATTEbakkegmxne@62.243.74.163>
T <myicqKATTE@bakkegmx.net> wrote in
news:Xns9AA76EBBC2E61myicqKATTEbakkegmxne@62.243.74.163:
> Yet, the TokeParser completely ignores that link. Why ?
SO obvious.. the site checks for automatic parsers and simply does not
display links... Load the site in IE and they are there.
So.. sorry for the question. I will post "solution" shortly.
------------------------------
Date: Fri, 23 May 2008 03:50:07 -0700 (PDT)
From: Leif Wessman <leifwessman@hotmail.com>
Subject: Using a buffer with HTTP::Response?
Message-Id: <f9c19800-9d97-48b3-9f11-a1dddabf11f0@f63g2000hsf.googlegroups.com>
I'm parsing a text-file, line by line. But it is almost 100 MB. Is it
possible to use a buffer instead of loading the complete text file
into memory?
This is the code I'm using today:
my $url = "http://datafeed.com/somefile.txt";
my $req = new HTTP::Request GET => $url;
my $ua = new LWP::UserAgent;
my $res = $ua->request($req);
if ($res->is_success) {
my @lines = split /\n/, $res->content;
foreach $line (@lines) {
# do stuff
}
}
Thanks!
------------------------------
Date: Fri, 23 May 2008 12:55:20 +0200
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Using a buffer with HTTP::Response?
Message-Id: <sf8d34p42r44ukrldm4b99uh7arhktc60o@hive.bjoern.hoehrmann.de>
* Leif Wessman wrote in comp.lang.perl.misc:
>I'm parsing a text-file, line by line. But it is almost 100 MB. Is it
>possible to use a buffer instead of loading the complete text file
>into memory?
>
>This is the code I'm using today:
>
>my $url = "http://datafeed.com/somefile.txt";
>my $req = new HTTP::Request GET => $url;
>my $ua = new LWP::UserAgent;
>my $res = $ua->request($req);
The second parameter to the request method takes a content callback,
you can also specify the special field :content_cb, see the notes in
`perldoc LWP::UserAgent` and see `perldoc lwpcook` for an example.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
------------------------------
Date: Fri, 23 May 2008 07:28:03 -0700 (PDT)
From: Alex Stankevich <astankevich@gmail.com>
Subject: Re: using m//g to parse multi-line records without an outside delimiter
Message-Id: <8835f25d-fbb6-4c1f-8079-8f7ff020ab27@f63g2000hsf.googlegroups.com>
These are all great suggestions, thanks!
I do have a further question to the split approach. I rewrote the code
as follows below. However, split seems to at first match an empty
string, and then breaks up the rest of the input into parts. Where
does the first empty string come from?
Thanks,
Alex.
---file: test_regex2.pl---
#!/usr/local/bin/perl
#
# test split in parsing multi-line records
#
undef $/;
print "---using split 1---\n";
@parts = split /^(From \w+\@xyz.com)$/m, <DATA>;
print "[$_]\n" foreach @parts;
print "---using split 2---\n";
@parts = split /^(From \w+\@xyz.com)$/m, <STDIN>;
print "[$_]\n" foreach @parts;
__DATA__
From mail@xyz.com
Header1: val1
To: abc@xyz.com
Subject: bla
body 1 of the email
From root@xyz.com
Header1: val1
To: abc@xyz.com
Subject: bla
body 2 of the email
From user01@xyz.com
Header1: val1
To: abc@xyz.com
Subject: bla
body 3 of the email
---file: test_regex_input.txt---
From mail@xyz.com
Header1: val1
To: abc@xyz.com
Subject: bla
body 1 of the email
From root@xyz.com
Header1: val1
To: abc@xyz.com
Subject: bla
body 2 of the email
From user01@xyz.com
Header1: val1
To: abc@xyz.com
Subject: bla
body 3 of the email
---two commands I ran and the output produced---
$ hexdump -C test_regex_input.txt
00000000 46 72 6f 6d 20 6d 61 69 6c 40 78 79 7a 2e 63 6f |From
mail@xyz.co|
00000010 6d 0a 48 65 61 64 65 72 31 3a 20 76 61 6c 31 0a |
m.Header1: val1.|
00000020 54 6f 3a 20 61 62 63 40 78 79 7a 2e 63 6f 6d 0a |To:
abc@xyz.com.|
00000030 53 75 62 6a 65 63 74 3a 20 62 6c 61 0a 0a 62 6f |Subject:
bla..bo|
00000040 64 79 20 31 20 6f 66 20 74 68 65 20 65 6d 61 69 |dy 1 of
the emai|
00000050 6c 0a 0a 46 72 6f 6d 20 72 6f 6f 74 40 78 79 7a |l..From
root@xyz|
00000060 2e 63 6f 6d 0a 48 65 61 64 65 72 31 3a 20 76 61
|.com.Header1: va|
00000070 6c 31 0a 54 6f 3a 20 61 62 63 40 78 79 7a 2e 63 |l1.To:
abc@xyz.c|
00000080 6f 6d 0a 53 75 62 6a 65 63 74 3a 20 62 6c 61 0a |
om.Subject: bla.|
00000090 0a 62 6f 64 79 20 32 20 6f 66 20 74 68 65 20 65 |.body 2
of the e|
000000a0 6d 61 69 6c 0a 0a 46 72 6f 6d 20 75 73 65 72 30 |
mail..From user0|
000000b0 31 40 78 79 7a 2e 63 6f 6d 0a 48 65 61 64 65 72 |
1@xyz.com.Header|
000000c0 31 3a 20 76 61 6c 31 0a 54 6f 3a 20 61 62 63 40 |1:
val1.To: abc@|
000000d0 78 79 7a 2e 63 6f 6d 0a 53 75 62 6a 65 63 74 3a |
xyz.com.Subject:|
000000e0 20 62 6c 61 0a 0a 62 6f 64 79 20 33 20 6f 66 20 |
bla..body 3 of |
000000f0 74 68 65 20 65 6d 61 69 6c 0a |the
email.|
000000fa
$ cat test_regex_input.txt | ./test_regex2.pl
---using split 1---
[]
[From mail@xyz.com]
[
Header1: val1
To: abc@xyz.com
Subject: bla
body 1 of the email
]
[From root@xyz.com]
[
Header1: val1
To: abc@xyz.com
Subject: bla
body 2 of the email
]
[From user01@xyz.com]
[
Header1: val1
To: abc@xyz.com
Subject: bla
body 3 of the email
]
---using split 2---
[]
[From mail@xyz.com]
[
Header1: val1
To: abc@xyz.com
Subject: bla
body 1 of the email
]
[From root@xyz.com]
[
Header1: val1
To: abc@xyz.com
Subject: bla
body 2 of the email
]
[From user01@xyz.com]
[
Header1: val1
To: abc@xyz.com
Subject: bla
body 3 of the email
]
------------------------------
Date: Fri, 23 May 2008 08:54:24 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: using m//g to parse multi-line records without an outside delimiter
Message-Id: <230520080854240998%jimsgibson@gmail.com>
In article
<8835f25d-fbb6-4c1f-8079-8f7ff020ab27@f63g2000hsf.googlegroups.com>,
Alex Stankevich <astankevich@gmail.com> wrote:
> These are all great suggestions, thanks!
>
> I do have a further question to the split approach. I rewrote the code
> as follows below. However, split seems to at first match an empty
> string, and then breaks up the rest of the input into parts. Where
> does the first empty string come from?
You have a substring that matches the delimiter pattern at the
beginning of your string. Therefore, your first "delimited" substring
is actually an empty string. You can test it for emptiness or filter it
out with grep.
From 'perldoc -f split':
"Empty leading (or trailing) fields are produced when there are
positive width matches at the beginning (or end) of the string"
--
Jim Gibson
------------------------------
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 1572
***************************************