[31389] in Perl-Users-Digest
Perl-Users Digest, Issue: 2641 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 19 14:30:12 2009
Date: Mon, 19 Oct 2009 11:30:03 -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 Mon, 19 Oct 2009 Volume: 11 Number: 2641
Today's topics:
MySQL RENAME TABLE error <john1949@yahoo.com>
Re: MySQL RENAME TABLE error <smallpond@juno.com>
Re: MySQL RENAME TABLE error <smallpond@juno.com>
Re: MySQL RENAME TABLE error <john1949@yahoo.com>
Novice Q: Can't use string ("X") as a symbol ref <ekononovich@gmail.com>
Re: Novice Q: Can't use string ("X") as a symbol ref <ben@morrow.me.uk>
Re: Novice Q: Can't use string ("X") as a symbol ref sln@netherlands.com
Re: Novice Q: Can't use string ("X") as a symbol ref <ekononovich@gmail.com>
parse multi line string into hash <user@example.net>
Re: parse multi line string into hash <tadmc@seesig.invalid>
Re: parse multi line string into hash sln@netherlands.com
Re: parse multi line string into hash sln@netherlands.com
Re: parse multi line string into hash sln@netherlands.com
Re: parse multi line string into hash <sreservoir@gmail.com>
Re: parse multi line string into hash sln@netherlands.com
Re: parse multi line string into hash sln@netherlands.com
Perl equivelent of "links -dump" <usenet05@drabble.me.uk>
Re: Perl equivelent of "links -dump" <devnull4711@web.de>
Re: Perl equivelent of "links -dump" <usenet05@drabble.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 17 Oct 2009 13:09:55 +0100
From: "John" <john1949@yahoo.com>
Subject: MySQL RENAME TABLE error
Message-Id: <hbcc67$neq$1@news.albasani.net>
Hi
This is just a snip of a program I don't know if it's a Perl or MySQL
problem
Basically, there is a list of tables in the array 'all'.
Prioblem = the program will create backups of all except the first table.
I can re-arrange the tables in the array 'all', but the first one still does
not get a backup created.
Any ideas?
John
for (my $j=0; $j<$total; $j++) {
my $table=$all[$j] ;
create_MySQL ($table)
}
sub create_MySQL {
my ($table)=@_;
my $backup='old_' . $table;
# backup existing table
my ($dbh,$sql,$sth);
$dbh=$library->MySQL_connection;
print "<hr>$table<hr>";
$sql="DROP TABLE IF EXISTS $backup"; $sth=$dbh->prepare($sql);
$sth->execute or die "Unable to execute query: $dbh->errstr<br>";
$sql="RENAME TABLE $table TO $backup"; $sth=$dbh->prepare($sql);
$sth->execute or die "Unable to execute query: $dbh->errstr<br>";
------------------------------
Date: Sat, 17 Oct 2009 12:59:13 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: MySQL RENAME TABLE error
Message-Id: <9bc0258b-e707-44d1-9596-45012c451976@m38g2000yqd.googlegroups.com>
On Oct 17, 8:09=A0am, "John" <john1...@yahoo.com> wrote:
> Hi
>
> This is just a snip of a program =A0I don't know if it's a Perl or MySQL
> problem
> Basically, there is a list of tables in the array 'all'.
> Prioblem =3D the program will create backups of all except the first tabl=
e.
> I can re-arrange the tables in the array 'all', but the first one still d=
oes
> not get a backup created.
>
> Any ideas?
> John
>
Somewhere above, you need to have:
use warnings;
use strict;
Otherwise everyone on this group will be mad at you.
> for (my $j=3D0; $j<$total; $j++) {
> =A0 =A0 my $table=3D$all[$j] ;
> =A0 =A0 create_MySQL ($table)
>
> }
Perl arrays know how big they are, so there is no need
for a separate variable $total.
This code is ok, but a more perlish way to write it would be:
foreach my $table (@all) {
create_MySQL($table);
}
>
> =A0sub create_MySQL {
> =A0 =A0 =A0 my ($table)=3D@_;
> =A0 =A0 =A0my $backup=3D'old_' . $table;
>
> =A0 =A0 =A0 # backup existing table
> =A0 =A0 =A0 my ($dbh,$sql,$sth);
> =A0 =A0 =A0 $dbh=3D$library->MySQL_connection;
> =A0 =A0 =A0print "<hr>$table<hr>";
Add delimiters around the name so you know there aren't extra chars:
print "<hr>::$table::<hr>";
> =A0 =A0 =A0 $sql=3D"DROP TABLE IF EXISTS $backup"; $sth=3D$dbh->prepare($=
sql);
> =A0 =A0 =A0 $sth->execute or die "Unable to execute query: $dbh->errstr<b=
r>";
> =A0 =A0 =A0 $sql=3D"RENAME TABLE $table TO $backup"; $sth=3D$dbh->prepare=
($sql);
> =A0 =A0 =A0$sth->execute or die "Unable to execute query: $dbh->errstr<br=
>";
Certainly looks like the perl is ok. Questions:
1) Is the first table appearing in the html output?
2) If so, how do you know the backup is not being created?
------------------------------
Date: Sat, 17 Oct 2009 13:06:52 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: MySQL RENAME TABLE error
Message-Id: <f2e981d3-70cf-4581-8c00-c983397f08df@l9g2000yqi.googlegroups.com>
On Oct 17, 3:59=A0pm, smallpond <smallp...@juno.com> wrote:
> On Oct 17, 8:09=A0am, "John" <john1...@yahoo.com> wrote:
>
> > Hi
>
> > This is just a snip of a program =A0I don't know if it's a Perl or MySQ=
L
> > problem
> > Basically, there is a list of tables in the array 'all'.
> > Prioblem =3D the program will create backups of all except the first ta=
ble.
> > I can re-arrange the tables in the array 'all', but the first one still=
does
> > not get a backup created.
>
> > Any ideas?
> > John
>
> Somewhere above, you need to have:
>
> use warnings;
> use strict;
>
> Otherwise everyone on this group will be mad at you.
>
> > for (my $j=3D0; $j<$total; $j++) {
> > =A0 =A0 my $table=3D$all[$j] ;
> > =A0 =A0 create_MySQL ($table)
>
> > }
>
> Perl arrays know how big they are, so there is no need
> for a separate variable $total.
>
> This code is ok, but a more perlish way to write it would be:
>
> foreach my $table (@all) {
> =A0 create_MySQL($table);
>
> }
>
> > =A0sub create_MySQL {
> > =A0 =A0 =A0 my ($table)=3D@_;
> > =A0 =A0 =A0my $backup=3D'old_' . $table;
>
> > =A0 =A0 =A0 # backup existing table
> > =A0 =A0 =A0 my ($dbh,$sql,$sth);
> > =A0 =A0 =A0 $dbh=3D$library->MySQL_connection;
> > =A0 =A0 =A0print "<hr>$table<hr>";
>
> Add delimiters around the name so you know there aren't extra chars:
> =A0 =A0 =A0 print "<hr>::$table::<hr>";
^^
not a good choice for delimiters. with more coffee i would say:
print "<hr>__${table}__<hr>";
>
> > =A0 =A0 =A0 $sql=3D"DROP TABLE IF EXISTS $backup"; $sth=3D$dbh->prepare=
($sql);
> > =A0 =A0 =A0 $sth->execute or die "Unable to execute query: $dbh->errstr=
<br>";
> > =A0 =A0 =A0 $sql=3D"RENAME TABLE $table TO $backup"; $sth=3D$dbh->prepa=
re($sql);
> > =A0 =A0 =A0$sth->execute or die "Unable to execute query: $dbh->errstr<=
br>";
>
> Certainly looks like the perl is ok. =A0Questions:
> 1) Is the first table appearing in the html output?
> 2) If so, how do you know the backup is not being created?
------------------------------
Date: Mon, 19 Oct 2009 12:55:58 +0100
From: "John" <john1949@yahoo.com>
Subject: Re: MySQL RENAME TABLE error
Message-Id: <hbhk41$28i$1@news.albasani.net>
"smallpond" <smallpond@juno.com> wrote in message
news:f2e981d3-70cf-4581-8c00-c983397f08df@l9g2000yqi.googlegroups.com...
On Oct 17, 3:59 pm, smallpond <smallp...@juno.com> wrote:
> On Oct 17, 8:09 am, "John" <john1...@yahoo.com> wrote:
>
> > Hi
>
> > This is just a snip of a program I don't know if it's a Perl or MySQL
> > problem
> > Basically, there is a list of tables in the array 'all'.
> > Prioblem = the program will create backups of all except the first
> > table.
> > I can re-arrange the tables in the array 'all', but the first one still
> > does
> > not get a backup created.
>
> > Any ideas?
> > John
>
> Somewhere above, you need to have:
>
> use warnings;
> use strict;
>
> Otherwise everyone on this group will be mad at you.
>
> > for (my $j=0; $j<$total; $j++) {
> > my $table=$all[$j] ;
> > create_MySQL ($table)
>
> > }
>
> Perl arrays know how big they are, so there is no need
> for a separate variable $total.
>
> This code is ok, but a more perlish way to write it would be:
>
> foreach my $table (@all) {
> create_MySQL($table);
>
> }
>
> > sub create_MySQL {
> > my ($table)=@_;
> > my $backup='old_' . $table;
>
> > # backup existing table
> > my ($dbh,$sql,$sth);
> > $dbh=$library->MySQL_connection;
> > print "<hr>$table<hr>";
>
> Add delimiters around the name so you know there aren't extra chars:
> print "<hr>::$table::<hr>";
^^
not a good choice for delimiters. with more coffee i would say:
print "<hr>__${table}__<hr>";
>
> > $sql="DROP TABLE IF EXISTS $backup"; $sth=$dbh->prepare($sql);
> > $sth->execute or die "Unable to execute query: $dbh->errstr<br>";
> > $sql="RENAME TABLE $table TO $backup"; $sth=$dbh->prepare($sql);
> > $sth->execute or die "Unable to execute query: $dbh->errstr<br>";
>
> Certainly looks like the perl is ok. Questions:
> 1) Is the first table appearing in the html output?
> 2) If so, how do you know the backup is not being created?
Hi
OK. Many thanks. I know there is no backup as I use PhpMyAdmin - a nice
GUI - to look at the tables.
So I now know it's a MySQL problem. I least I know where to look.
Regards
John
------------------------------
Date: Wed, 14 Oct 2009 15:36:56 -0700 (PDT)
From: "Yevgeniy K." <ekononovich@gmail.com>
Subject: Novice Q: Can't use string ("X") as a symbol ref
Message-Id: <7a545de4-c029-4aa3-9c11-06ddb44002b2@p4g2000yqm.googlegroups.com>
I have the following code to open a file:
use strict;
sub open_file {
my ($file, $FILE) = @_;
unless (open ($FILE, ">>$file")) { die "error msg\n" }
}
And at runtime I get: "Can't use string ("LIST") as a symbol ref while
"strict refs" in use"
Maybe my understanding of references is incorrect, but I fail to grasp
why this is a reference. I assign the value of local scalar variable
$FILE to the second argument passed to the subroutine, which in this
case happens to be "LIST"; then use that scalar var instead of a
literal to set the filehandle--what is the problem? Please advise!
Thanks in advance!
------------------------------
Date: Thu, 15 Oct 2009 00:31:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Novice Q: Can't use string ("X") as a symbol ref
Message-Id: <5j3iq6-1bf.ln1@osiris.mauzo.dyndns.org>
Quoth "Yevgeniy K." <ekononovich@gmail.com>:
> I have the following code to open a file:
>
> use strict;
>
> sub open_file {
> my ($file, $FILE) = @_;
> unless (open ($FILE, ">>$file")) { die "error msg\n" }
> }
>
> And at runtime I get: "Can't use string ("LIST") as a symbol ref while
> "strict refs" in use"
>
> Maybe my understanding of references is incorrect, but I fail to grasp
> why this is a reference. I assign the value of local scalar variable
> $FILE to the second argument passed to the subroutine, which in this
> case happens to be "LIST"; then use that scalar var instead of a
> literal to set the filehandle--what is the problem? Please advise!
This is quite a complicated question :). When you say
open LIST, ...;
what you really mean is
open \*LIST, ...;
so you are using the (unquoted) string "LIST" as a symbolic ref to the
glob *LIST. Perl makes a special exception to strict 'vars' and strict
'subs' for this usage, since it's needed to reopen STDIN, STDOUT and
STDERR. This exception only applied to *unquoted* strings, which are
actually compiled as though you used the proper ref syntax in the first
place.
In any case, you shouldn't be using bareword filehandles in modern Perl.
Instead of
open LIST, ">>$file";
you should use
open my $LIST, ">>", $file;
which puts the filehandle in a properly-scoped variable. (The 3-arg open
is a separate improvement, which avoids issues with filenames with funny
characters in them.)
This is, however, a little tricky if you want a sub to open a filehandle
for you. The best answer is to have the sub return the filehandle, and
assign it to a variable, like
use warnings;
use strict;
sub open_file {
my ($file) = @_;
my $FILE;
unless (open ($FILE, ">>$file")) { die "error msg\n" }
return $FILE;
}
my $LIST = open_file "file";
Ben
------------------------------
Date: Wed, 14 Oct 2009 17:15:23 -0700
From: sln@netherlands.com
Subject: Re: Novice Q: Can't use string ("X") as a symbol ref
Message-Id: <i1qcd55r7k9kuuhj5tn60u2r6q5rc1veub@4ax.com>
On Wed, 14 Oct 2009 15:36:56 -0700 (PDT), "Yevgeniy K." <ekononovich@gmail.com> wrote:
>I have the following code to open a file:
>
>use strict;
>
>sub open_file {
> my ($file, $FILE) = @_;
> unless (open ($FILE, ">>$file")) { die "error msg\n" }
>}
>
>And at runtime I get: "Can't use string ("LIST") as a symbol ref while
>"strict refs" in use"
>
>Maybe my understanding of references is incorrect, but I fail to grasp
>why this is a reference. I assign the value of local scalar variable
>$FILE to the second argument passed to the subroutine, which in this
>case happens to be "LIST"; then use that scalar var instead of a
>literal to set the filehandle--what is the problem? Please advise!
>Thanks in advance!
Its all mucky stuff, barewords, symbols, filehandles.
Any scalar can be used in an open, it depends upon whats in the variable
and if "strict refs" are in effect.
These are some options. What's in the textfile.txt after you do the below?
my $FILE = "LIST";
open ($FILE, '>>', "textfile.txt") or die $!;
print $FILE "\"LIST\"\n";
close $FILE;
use strict;
use warnings;
$FILE = *LIST;
open ($FILE, '>>', "textfile.txt") or die $!;
print $FILE "*LIST\n";
close $FILE;
$FILE = \*LIST;
open ($FILE, '>>', "textfile.txt") or die $!;
print $FILE "\\*LIST\n";
close $FILE;
$FILE = undef;
open ($FILE, '>>', "textfile.txt") or die $!;
print $FILE "undef\n";
close $FILE;
my $FOO = $FILE;
open ($FOO, '>>', "textfile.txt") or die $!;
print $FOO "FOO = FILE\n";
close $FOO;
$FILE = "LIST";
open ($FILE, '>>', "textfile.txt") or die $!;
print $FILE "\"LIST\"\n";
close $FILE;
-sln
------------------------------
Date: Thu, 15 Oct 2009 15:16:54 -0700 (PDT)
From: "Yevgeniy K." <ekononovich@gmail.com>
Subject: Re: Novice Q: Can't use string ("X") as a symbol ref
Message-Id: <359d4da3-7d85-415c-b3be-1646cf9476f3@e8g2000yqo.googlegroups.com>
Thank you for the responses!!
------------------------------
Date: Fri, 16 Oct 2009 14:05:18 -0400
From: monkeys paw <user@example.net>
Subject: parse multi line string into hash
Message-Id: <jvWdnRL_w4JxKEXXnZ2dnUVZ_tCdnZ2d@insightbb.com>
I need to parse the following string into a hash. The string includes
the spaces shown also. How can i get $string into %hash. I can't split
on commas because some of the hash values have
commas (see states => CA,KY...). So how would i split on newlines
to do this is my question. I need hash to be
$hash{disposition} = 1;
$hash{billkey} = 'CA:2009000:A:708';
etc..
my $string = 'disposition => 1,
billkey => CA:2009000:A:708,
max_bills => 1000,
states => CA,KY,FL,
print_pfdata => 1,
query_type => single,
range => 0,
active => 1,
#print_authors => 1,
remote_user => zamktph,
keys => [
{
id_type => bill,
id => CA2009000A708
}
],
id_type => bill,
network_code => NON,
no_topics => 1,';
------------------------------
Date: Fri, 16 Oct 2009 14:49:08 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: parse multi line string into hash
Message-Id: <slrnhdhil3.ngb.tadmc@tadmc30.sbcglobal.net>
monkeys paw <user@example.net> wrote:
> I need to parse the following string into a hash. The string includes
> the spaces shown also. How can i get $string into %hash. I can't split
> on commas because some of the hash values have
> commas (see states => CA,KY...). So how would i split on newlines
> to do this is my question. I need hash to be
>
> $hash{disposition} = 1;
> $hash{billkey} = 'CA:2009000:A:708';
> etc..
What should $hash{keys} look like?
I'll leave that as an exercise for the reader...
--------------------------
#!/usr/bin/perl
use warnings;
use strict;
my $string = 'disposition => 1,
billkey => CA:2009000:A:708,
max_bills => 1000,
states => CA,KY,FL,
print_pfdata => 1,
query_type => single,
range => 0,
active => 1,
#print_authors => 1,
remote_user => zamktph,
keys => [
{
id_type => bill,
id => CA2009000A708
}
],
id_type => bill,
network_code => NON,
no_topics => 1,';
my %hash = split /\s*=>\s*|,\n\s*/, $string;
use Data::Dumper;
print Dumper \%hash;
--------------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 16 Oct 2009 14:50:20 -0700
From: sln@netherlands.com
Subject: Re: parse multi line string into hash
Message-Id: <3gqhd594r83fr005pnoi4qeslnlrnamb14@4ax.com>
On Fri, 16 Oct 2009 14:05:18 -0400, monkeys paw <user@example.net> wrote:
>I need to parse the following string into a hash. The string includes
>the spaces shown also. How can i get $string into %hash. I can't split
>on commas because some of the hash values have
>commas (see states => CA,KY...). So how would i split on newlines
>to do this is my question. I need hash to be
>
>$hash{disposition} = 1;
>$hash{billkey} = 'CA:2009000:A:708';
>etc..
>
>
>my $string = 'disposition => 1,
> billkey => CA:2009000:A:708,
> max_bills => 1000,
> states => CA,KY,FL,
> print_pfdata => 1,
> query_type => single,
> range => 0,
> active => 1,
> #print_authors => 1,
> remote_user => zamktph,
> keys => [
> {
> id_type => bill,
> id => CA2009000A708
> }
> ],
> id_type => bill,
> network_code => NON,
> no_topics => 1,';
How $string ever got into this shape is pure speculation.
To reverse it is not a pleasure.
-sln
use strict;
use warnings;
use Data::Dumper;
my $string = 'disposition => 1,
billkey => CA:2009000:A:708,
max_bills => 1000,
states => CA,KY,FL,
print_pfdata => 1,
query_type => single,
range => 0,
active => 1,
#print_authors => 1,
remote_user => zamktph,
keys => [
{
id_type => bill,
id => CA2009000A708
}
],
id_type => bill,
network_code => NON,
test =>,
no_topics => 1,';
## one pass ..
## $string =~ s/ => \s* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
## or, two pass ..
$string =~ s/ ( => \s* (?![\[\{\n\s])) /$1'/xg;
$string =~ s/ ( (?![\[\]\{\},\n]).) (,|)(\n|$) /$1'$2\n/xg;
print $string;
my %hash = eval $string;
print Dumper (\%hash);
__END__
disposition => '1',
billkey => 'CA:2009000:A:708',
max_bills => '1000',
states => 'CA,KY,FL',
print_pfdata => '1',
query_type => 'single',
range => '0',
active => '1',
#print_authors => '1',
remote_user => 'zamktph',
keys => [
{
id_type => 'bill',
id => 'CA2009000A708'
}
],
id_type => 'bill',
network_code => 'NON',
test =>'',
no_topics => '1',
$VAR1 = {
'billkey' => 'CA:2009000:A:708',
'disposition' => '1',
'test' => '',
'max_bills' => '1000',
'query_type' => 'single',
'active' => '1',
'range' => '0',
'states' => 'CA,KY,FL',
'keys' => [
{
'id_type' => 'bill',
'id' => 'CA2009000A708'
}
],
'remote_user' => 'zamktph',
'id_type' => 'bill',
'print_pfdata' => '1',
'network_code' => 'NON',
'no_topics' => '1'
};
------------------------------
Date: Sat, 17 Oct 2009 12:13:37 -0700
From: sln@netherlands.com
Subject: Re: parse multi line string into hash
Message-Id: <0f4kd59qbmsdciu3hl7cc7a2mq84en7cm5@4ax.com>
On Fri, 16 Oct 2009 14:50:20 -0700, sln@netherlands.com wrote:
>## one pass ..
>## $string =~ s/ => \s* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>
>## or, two pass ..
>$string =~ s/ ( => \s* (?![\[\{\n\s])) /$1'/xg;
>$string =~ s/ ( (?![\[\]\{\},\n]).) (,|)(\n|$) /$1'$2\n/xg;
>
And, to allow for -
atest => + whitespace,newline or eos: (\s*(\n|$))
or
atest => ,,,, + newline
--------------
## one pass ..
# $string =~ s/ => (?:(?!\n)\s)* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
## or, two pass ..
$string =~ s/ => (?:(?!\n|$)\s)* (?=\n|$|[^\[\{\s]) (\n|$|) /=> '$1/xg;
$string =~ s/ ( (?![\[\]\{\}\n]|,\s*(?:\n|$)).) (,|) \s* (\n|$) /$1',\n/xg;
One pass seems more efficient, both produce same results.
-sln
------------------------------
Date: Sat, 17 Oct 2009 12:25:39 -0700
From: sln@netherlands.com
Subject: Re: parse multi line string into hash
Message-Id: <836kd5d978f44dje0d9n6qs2rga3qejt99@4ax.com>
On Sat, 17 Oct 2009 12:13:37 -0700, sln@netherlands.com wrote:
>On Fri, 16 Oct 2009 14:50:20 -0700, sln@netherlands.com wrote:
>
>>## one pass ..
>>## $string =~ s/ => \s* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>>
>>## or, two pass ..
>>$string =~ s/ ( => \s* (?![\[\{\n\s])) /$1'/xg;
>>$string =~ s/ ( (?![\[\]\{\},\n]).) (,|)(\n|$) /$1'$2\n/xg;
>>
>
>And, to allow for -
> atest => + whitespace,newline or eos: (\s*(\n|$))
>or
> atest => ,,,, + newline
>
>--------------
>## one pass ..
># $string =~ s/ => (?:(?!\n)\s)* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>
>## or, two pass ..
> $string =~ s/ => (?:(?!\n|$)\s)* (?=\n|$|[^\[\{\s]) (\n|$|) /=> '$1/xg;
> $string =~ s/ ( (?![\[\]\{\}\n]|,\s*(?:\n|$)).) (,|) \s* (\n|$) /$1',\n/xg;
>
>One pass seems more efficient, both produce same results.
(?:(?!\n)\s)* could be replaced by this [\ \t\r\f]*
-sln
------------------------------
Date: Sat, 17 Oct 2009 15:45:13 -0400
From: sreservoir <sreservoir@gmail.com>
Subject: Re: parse multi line string into hash
Message-Id: <hbd6rl$etl$1@aioe.org>
sln@netherlands.com wrote:
> On Sat, 17 Oct 2009 12:13:37 -0700, sln@netherlands.com wrote:
>
>> On Fri, 16 Oct 2009 14:50:20 -0700, sln@netherlands.com wrote:
>>
>>> ## one pass ..
>>> ## $string =~ s/ => \s* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>>>
>>> ## or, two pass ..
>>> $string =~ s/ ( => \s* (?![\[\{\n\s])) /$1'/xg;
>>> $string =~ s/ ( (?![\[\]\{\},\n]).) (,|)(\n|$) /$1'$2\n/xg;
>>>
>> And, to allow for -
>> atest => + whitespace,newline or eos: (\s*(\n|$))
>> or
>> atest => ,,,, + newline
>>
>> --------------
>> ## one pass ..
>> # $string =~ s/ => (?:(?!\n)\s)* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>>
>> ## or, two pass ..
>> $string =~ s/ => (?:(?!\n|$)\s)* (?=\n|$|[^\[\{\s]) (\n|$|) /=> '$1/xg;
>> $string =~ s/ ( (?![\[\]\{\}\n]|,\s*(?:\n|$)).) (,|) \s* (\n|$) /$1',\n/xg;
>>
>> One pass seems more efficient, both produce same results.
>
> (?:(?!\n)\s)* could be replaced by this [\ \t\r\f]*
> -sln
[^\S\n]
--
"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe"
------------------------------
Date: Sat, 17 Oct 2009 13:51:12 -0700
From: sln@netherlands.com
Subject: Re: parse multi line string into hash
Message-Id: <fhbkd51l3vaqfoltst90stl5tbei8gbmno@4ax.com>
On Sat, 17 Oct 2009 15:45:13 -0400, sreservoir <sreservoir@gmail.com> wrote:
>sln@netherlands.com wrote:
>> On Sat, 17 Oct 2009 12:13:37 -0700, sln@netherlands.com wrote:
>>
>>> On Fri, 16 Oct 2009 14:50:20 -0700, sln@netherlands.com wrote:
>>>
>>>> ## one pass ..
>>>> ## $string =~ s/ => \s* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>>>>
>>>> ## or, two pass ..
>>>> $string =~ s/ ( => \s* (?![\[\{\n\s])) /$1'/xg;
>>>> $string =~ s/ ( (?![\[\]\{\},\n]).) (,|)(\n|$) /$1'$2\n/xg;
>>>>
>>> And, to allow for -
>>> atest => + whitespace,newline or eos: (\s*(\n|$))
>>> or
>>> atest => ,,,, + newline
>>>
>>> --------------
>>> ## one pass ..
>>> # $string =~ s/ => (?:(?!\n)\s)* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>>>
>>> ## or, two pass ..
>>> $string =~ s/ => (?:(?!\n|$)\s)* (?=\n|$|[^\[\{\s]) (\n|$|) /=> '$1/xg;
>>> $string =~ s/ ( (?![\[\]\{\}\n]|,\s*(?:\n|$)).) (,|) \s* (\n|$) /$1',\n/xg;
>>>
>>> One pass seems more efficient, both produce same results.
>>
>> (?:(?!\n)\s)* could be replaced by this [\ \t\r\f]*
>> -sln
>
>[^\S\n]
Thanks!
-sln
------------------------------
Date: Sat, 17 Oct 2009 14:15:04 -0700
From: sln@netherlands.com
Subject: Re: parse multi line string into hash
Message-Id: <9mckd55vu7oj4gt6u8oc9t2uk3dcoef302@4ax.com>
On Sat, 17 Oct 2009 12:25:39 -0700, sln@netherlands.com wrote:
>On Sat, 17 Oct 2009 12:13:37 -0700, sln@netherlands.com wrote:
>
>>On Fri, 16 Oct 2009 14:50:20 -0700, sln@netherlands.com wrote:
>>
>>>## one pass ..
>>>## $string =~ s/ => \s* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>>>
>>>## or, two pass ..
>>>$string =~ s/ ( => \s* (?![\[\{\n\s])) /$1'/xg;
>>>$string =~ s/ ( (?![\[\]\{\},\n]).) (,|)(\n|$) /$1'$2\n/xg;
>>>
>>
>>And, to allow for -
>> atest => + whitespace,newline or eos: (\s*(\n|$))
>>or
>> atest => ,,,, + newline
>>
>>--------------
>>## one pass ..
>># $string =~ s/ => (?:(?!\n)\s)* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
>>
>>## or, two pass ..
>> $string =~ s/ => (?:(?!\n|$)\s)* (?=\n|$|[^\[\{\s]) (\n|$|) /=> '$1/xg;
>> $string =~ s/ ( (?![\[\]\{\}\n]|,\s*(?:\n|$)).) (,|) \s* (\n|$) /$1',\n/xg;
>>
>>One pass seems more efficient, both produce same results.
>
>(?:(?!\n)\s)* could be replaced by this [\ \t\r\f]*
[^\S\n] pointed out by sreservoir, works better.
## one pass ..
# $string =~ s/ => [^\S\n]* ( (?:(?!,\s*(?:\n|$))[^\[\{\n]+?)* |) ,?\s*(?:\n|$) /=> '$1',\n/xg;
## or, two pass ..
$string =~ s/ => [^\S\n]* (?=\n|$|[^\[\{\s]) (\n|$|) /=> '$1/xg;
$string =~ s/ ( (?![\[\]\{\}\n]|,\s*(?:\n|$)).) (,|) \s* (\n|$) /$1',\n/xg;
------------------------------
Date: Sun, 18 Oct 2009 10:54:51 +0100
From: Graham Drabble <usenet05@drabble.me.uk>
Subject: Perl equivelent of "links -dump"
Message-Id: <Xns9CA86F06E258Fgrahamdrabblelineone@drabble.me.uk>
Hi,
I currently have a script running under linux that uses
$str = `links -dump -width 72 $url`;
However I want to write this entirely in Perl so that it is easy to
port between systems, including systems that don't have links.
(For those that don't understand the call to links, it outputs a text
only representation of the HTML document formatted to keep within 72
characters.)
I've tried just reading in the raw HTML and tag stripping but that
fails because the underlying HTML may not be formatted nicely. I need
something that will properly parse the HTML to generate the text
layout.
I'm sure that this must have been done several times before but can't
find anything on CPAN. Any ideas?
--
Graham Drabble
http://www.drabble.me.uk/
------------------------------
Date: Sun, 18 Oct 2009 14:48:15 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Perl equivelent of "links -dump"
Message-Id: <7k0h2uF37g82iU1@mid.individual.net>
Graham Drabble wrote:
>
> I'm sure that this must have been done several times before but can't
> find anything on CPAN. Any ideas?
HTML::Formatter?
Frank
--
Dipl.-Inform. Frank Seitz
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
Homepage: http://www.fseitz.de/
XING-Profil: http://www.xing.com/profile/Frank_Seitz2
------------------------------
Date: Sun, 18 Oct 2009 16:43:43 +0100
From: Graham Drabble <usenet05@drabble.me.uk>
Subject: Re: Perl equivelent of "links -dump"
Message-Id: <Xns9CA8AA2CCDDA2grahamdrabblelineone@drabble.me.uk>
On 18 Oct 2009 Frank Seitz <devnull4711@web.de> wrote in
news:7k0h2uF37g82iU1@mid.individual.net:
> HTML::Formatter
That's the one. Many thanks.
--
Graham Drabble
http://www.drabble.me.uk/
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2641
***************************************