[24069] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6264 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 16 11:05:42 2004

Date: Tue, 16 Mar 2004 08:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 16 Mar 2004     Volume: 10 Number: 6264

Today's topics:
    Re: All capital permutations of a string? <vetro@online.no>
    Re: block of code doesn't get executed (Anno Siegel)
    Re: block of code doesn't get executed <dwall@fastmail.fm>
    Re: browser tries to download perl code <tore@aursand.no>
    Re: call a cgi script from a cgi script (Joe)
    Re: Error installing CPAN module [FIXED!] <knocte@NO-SPAM-PLEASE-hotmail.com>
        Error installing CPAN module <knocte@NO-SPAM-PLEASE-hotmail.com>
    Re: Error installing CPAN module <roel-perl@st2x.net>
    Re: Error installing CPAN module <knocte@NO-SPAM-PLEASE-hotmail.com>
    Re: Hash as a function argument.. plz help! (Bart Van der Donck)
    Re: Hash as a function argument.. plz help! (Anno Siegel)
        Having problems with with the s/// substitution (Hakan Bacakoglu)
    Re: incrementing a string by a certain value <tore@aursand.no>
    Re: incrementing a string by a certain value <gned@telsmonopolytradotcom.remove.monopoly)>
    Re: incrementing a string by a certain value <roel-perl@st2x.net>
        Problems installing IO::Tty locally (Roger Broadbent)
    Re: Regex to match simple line of XML (ac)
    Re: system(...) does not produce output using 5.8.* <roel-perl@st2x.net>
        Transparently Intercepting Mail <witsuk@btopenworld.com>
    Re: variable initialization question <nobull@mail.com>
    Re: variable initialization question <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 16 Mar 2004 12:45:08 +0100
From: Vetle Roeim <vetro@online.no>
Subject: Re: All capital permutations of a string?
Message-Id: <m3y8q1rp6j.fsf@quimby.dirtyhack.org>

* joeblow341@hotmail.com
> Does anyone have an elegant way of, given a string, generate all possible 
> capitalization permutations of that string?  ie:
>
> 000  abc
> 001  abC
> 010  aBc
> 011  aBC
> 100  Abc
> 101  AbC
> etc.
>
> The only method I can come up with, which to me seems a little brute 
> force, is to create a  
> truth table, then compare each element of the array, stuffing the 
> corresponding element of the array with a lower or uppercase letter from 
> the corresponding element of the string. (0 would get lower, 1 upper).
>
> Any one have any more interesting ideas?  I don't need to keep the 
> permutations in memory, just create it and spit it out to STDOUT.

  Here's one way to do it (I borrowed a few ideas from some other
  suggestions :)).

    use strict;
    use warnings;

    sub permutations {
        my ($string) = @_;
        return ('') if ( not( length $string ) ) ;

        my ($car, $cddr) = $string =~ /(.)(.*)/ ;
        my @result = map { $car . $_, uc($car) . $_ } permutations( $cddr );
    }

    permutations( 'abc' );



-- 
#!/usr/bin/vr


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

Date: 16 Mar 2004 12:43:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: block of code doesn't get executed
Message-Id: <c36sq6$oj4$1@mamenchi.zrz.TU-Berlin.DE>

Dave Cross  <dave@dave.org.uk> wrote in comp.lang.perl.misc:
> On Tue, 16 Mar 2004 02:09:44 +0000, Jürgen Exner wrote:
> 
> > David K. Wall wrote:
> >> stalwart <hammer@thatbox.net> wrote:
> > [...]
> >>>                 s/^_RC//;
> >>>                 s/_RC^/"\n"/;
> >>
> >> A carat (^) in a regex means the beginning of a string.  How can
> >> '_RC' be *before* the beginning of the string?
> > 
> > Almost right. A carat matches the beginning of the string iff it is at the
> > beginning of the RE. Otherwise it is just an ordinary character.
> 
> Or if the /m option is used.

 ...and s/carat/caret/g

Anno


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

Date: Tue, 16 Mar 2004 15:32:18 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: block of code doesn't get executed
Message-Id: <Xns94AE6B33B3F3Fdkwwashere@216.168.3.30>

stalwart <hammer@thatbox.net> wrote:

> "David K. Wall" <dwall@fastmail.fm> wrote in message
> news:<Xns94AD976B083A1dkwwashere@216.168.3.30>... 
>> stalwart <hammer@thatbox.net> wrote:
 
>> > print("Getting directory listing of mp3s.....\n");
>> > %filename =  $ftp->ls
>> >       or die "Unable to list the dir!:\n", $ftp->message;
>> 
>> The 'ls' method returns a list, which this code... puts into a hash? 
>> Probably not what you want.
> 
> My intention was to have the filenames in a hash so i could call them
> individually with keys to compare file by file the unix timestamps. 
> Perhaps I should use an array instead or just not bother with
> something like that?

Depends on what you want. You could retrieve the names and then use them to 
initialize a hash:

my @names $ftp->ls or die "Unable to list the dir!:\n", $ftp->message;
my %files;
@files{@names} = ();

Now you have a hash with the proper keys and undefined values, which you 
can fill in as you please.  'perldoc perldsc' -- the Perl Data Structures 
Cookbook -- might be helpful.  See perlreftut and perlref for background 
info.

>> >                 s/^_RC//;
>> >                 s/_RC^/"\n"/;
>> 
>> A carat (^) in a regex means the beginning of a string.  How can '_RC'
>> be *before* the beginning of the string? 
> 
> Good point, my mistake.  

I was wrong. See Jürgen Exner's followup.

>   I had thought it meant everything before THAT
> string..when I get an ls using the FTP module i needed to get rid of
> everything BEFORE the _RC string...again, my mistake.

OK, we were both wrong. :-)  

>> I get the impression you're confused about Perl data types. %filename, 
>> @filename, and $filename can exist in the same program, but they don't 
>> necessarily have *anything* to do with each other. They are completely 
>> different variables.
> 
> I suppose I am.  I had the impression you could call an array or hash
> as $ARRAY or $HASH after they were defined.

Sort of.  If you have %hash then $hash{$key} is one element of that hash. 
To get multiple elements you can use a hash slice as I did above, e.g.; 
@hash{@keys}.

-- 
David Wall


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

Date: Tue, 16 Mar 2004 15:21:46 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: browser tries to download perl code
Message-Id: <pan.2004.03.16.14.08.11.730450@aursand.no>

On Tue, 16 Mar 2004 08:29:58 +0000, Dave Cross wrote:
>> my $CGI = CGI->new();
>> print $CGI->header(-type => 'text/html');

> If you're importing functions into your namespace ("use CGI qw(:cgi)")
> then why bother creating a CGI object? The :cgi export group includes
> the "header" function.

That's right;  When I posted the message I was unsure if I should stick to
the function oriented or the object oriented style.  I got stuck with both
of them, obviously. :)

> Also text/html is the default type used by "header".

Also correct, although I find it less confusing to be consistent about
what header type you're outputting.

One other thing;  I prefer the object oriented style, 'cause it gives you
the opportunity to have multiple CGI objects (at the same time), and it
also makes function name conflicts impossible.  Imagine this code;

  #!/usr/bin/perl
  #
  use strict;
  use warnings;
  use CGI qw(:cgi);

  print header();

  sub header {
      return 'Haha!';
  }

Not the best example, but... :)


-- 
Tore Aursand <tore@aursand.no>
"Scientists are complaining that the new "Dinosaur" movie shows
 dinosaurs with lemurs, who didn't evolve for another million years.
 They're afraid the movie will give kids a mistaken impression. What
 about the fact that the dinosaurs are singing and dancing?" -- Jay
 Leno


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

Date: 16 Mar 2004 05:29:17 -0800
From: jab_joe@www.com (Joe)
Subject: Re: call a cgi script from a cgi script
Message-Id: <6586e7f6.0403160529.7e5ac0cf@posting.google.com>

Glenn Jackman <xx087@freenet.carleton.ca> wrote in message news:<slrnc5bpjf.j9q.xx087@smeagol.ncf.ca>...
> Joe <jab_joe@www.com> wrote:
> [...]  
> >  system ("perl $SCRIPT_URL");
> >  
> >  The problem with this is it doesn't force a re-fresh of the existing
> >  page. The text of the page before is still there.
> 
> Perhaps you should set the web server to the work for you:
>     print $cgi->redirect($SCRIPT_URL)
> And then that cgi can redirect back to you.

my $cgi = new CGI;

$cgi->redirect(-URL =>
"http://www.mywebsite.com/myscript.cgi?MYARGUMENT\", -nph=>1);

This just makes everything blank.......... I'm obviously missing
something.
(and yes, my script works fine when called with that url manually).

Doing:

print "<meta http-equiv=\"REFRESH\" content=\"1;
URL=\"http://www.mywebsite.com/myscript.cgi?MYARGUMENT\">"

mean I get a loop because MYARGUMENT doesn't come in as the argument
for some reason. If it did, I would be sorted.


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

Date: Tue, 16 Mar 2004 16:47:55 +0100
From: knocte <knocte@NO-SPAM-PLEASE-hotmail.com>
Subject: Re: Error installing CPAN module [FIXED!]
Message-Id: <c377d7$4sh$1@nsnmpen2-gest.nuria.telefonica-data.net>

[I wrote]:
> Sorry, I don't know if this is the correct group to post this.
> 
> If I write the command perl -MCPAN -e 'install "DBD::mysql"', this error 
> is presented:
> 
> Checking if your kit is complete...
> Looks good
> Using DBI 1.40 (for perl 5.008003 on i386-linux-thread-multi) installed 
> in /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi/auto/DBI
> Writing Makefile for DBD::mysql
> make: *** No hay ninguna regla para construir el objetivo 
> `/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE/config.h', necesario 
> para `Makefile'.  Alto.
>   /usr/bin/make  -- NOT OK
> Running make test
>   Can't test without successful make
> Running make install
>   make had returned bad status, install seems impossible
> 
> Anyone know what's my problem? Thanks in advance.
> 
> PS: The same error occurs if I try to install any other CPAN module.
> PS II: Some messages in the error are translated by my distribution into 
> spanish. A traduction to English could be:
> 
> *** No rule to make target 
> `/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE/config.h', needed by 
> `Makefile'.  Stop.

DUMB! It's fixed now, I didn't install the packet perl-devel!


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

Date: Tue, 16 Mar 2004 11:09:45 GMT
From: knocte <knocte@NO-SPAM-PLEASE-hotmail.com>
Subject: Error installing CPAN module
Message-Id: <ZfB5c.3983057$uj6.12304498@telenews.teleline.es>

Sorry, I don't know if this is the correct group to post this.

If I write the command perl -MCPAN -e 'install "DBD::mysql"', this error 
is presented:

Checking if your kit is complete...
Looks good
Using DBI 1.40 (for perl 5.008003 on i386-linux-thread-multi) installed 
in /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi/auto/DBI
Writing Makefile for DBD::mysql
make: *** No hay ninguna regla para construir el objetivo 
`/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE/config.h', necesario 
para `Makefile'.  Alto.
   /usr/bin/make  -- NOT OK
Running make test
   Can't test without successful make
Running make install
   make had returned bad status, install seems impossible

Anyone know what's my problem? Thanks in advance.

PS: The same error occurs if I try to install any other CPAN module.
PS II: Some messages in the error are translated by my distribution into 
spanish. A traduction to English could be:

*** No rule to make target 
`/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE/config.h', needed by 
`Makefile'.  Stop.


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

Date: 16 Mar 2004 12:04:17 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: Error installing CPAN module
Message-Id: <slrnc5drau.rts.roel-perl@localhost.localdomain>

On Tue, 16 Mar 2004 at 11:09 GMT, knocte wrote:
> *** No rule to make target 
> `/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE/config.h', needed by 
> `Makefile'.  Stop.

Have you checked if the file config.h is there?


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

Date: Tue, 16 Mar 2004 16:27:07 +0100
From: knocte <knocte@NO-SPAM-PLEASE-hotmail.com>
Subject: Re: Error installing CPAN module
Message-Id: <c3766d$j4$1@nsnmpen2-gest.nuria.telefonica-data.net>

Roel van der Steen escribió:
> On Tue, 16 Mar 2004 at 11:09 GMT, knocte wrote:
> 
>>*** No rule to make target 
>>`/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE/config.h', needed by 
>>`Makefile'.  Stop.
> 
> 
> Have you checked if the file config.h is there?

Thanks for your reply.

That file doesn't exist. Must I create it with no content? The only file 
with that name in my box is in /usr/include/linux/.

Regards,

	knocte


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

Date: 16 Mar 2004 04:00:35 -0800
From: bart@nijlen.com (Bart Van der Donck)
Subject: Re: Hash as a function argument.. plz help!
Message-Id: <b5884818.0403160400.22d73172@posting.google.com>

> # Why won't this work..
> fun ("whatever", %map);
> 
> # But this will ?!
> fun ("again",
>      'a' => 'first char', 'b' => 'second');
> --- snip snip
> 
> What am I doing wrong (obviously near the comment mark "why won't this
> work")? Any and all help will be appreciated!
 
 
You should declare your hash by ()-signs and not by {}-signs. In your code:

my %map = (
     1 => 'one',
     2 => 'two',
     3 => 'three',
);

Regards,
Bart


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

Date: 16 Mar 2004 13:00:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Hash as a function argument.. plz help!
Message-Id: <c36tq2$oj4$2@mamenchi.zrz.TU-Berlin.DE>

Bart Van der Donck <bart@nijlen.com> wrote in comp.lang.perl.misc:
> > # Why won't this work..
> > fun ("whatever", %map);
> > 
> > # But this will ?!
> > fun ("again",
> >      'a' => 'first char', 'b' => 'second');
> > --- snip snip
> > 
> > What am I doing wrong (obviously near the comment mark "why won't this
> > work")? Any and all help will be appreciated!
>  
>  
> You should declare your hash by ()-signs and not by {}-signs. In your code:
             ^^^^^^^
> my %map = (
>      1 => 'one',
>      2 => 'two',
>      3 => 'three',
> );

That's not declaration, it's assignment.  The declaration is "my %map".

Sorry for the nitpick, but "declaration" and "assignment" (or
"initialization") are often confused.  We have an ongoing thread
where this lead to a misunderstanding.

Anno


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

Date: 16 Mar 2004 08:01:44 -0800
From: hbacakoglu@hotmail.com (Hakan Bacakoglu)
Subject: Having problems with with the s/// substitution
Message-Id: <bcd6537e.0403160801.190c44aa@posting.google.com>

Folks,

Please help me out with this: I am reading a file WEBINP and trying to
replace a pattern which exists multiple times in each line. The
replacement ($1) is called out of a subroutine.

The problem is when I try to do substitution at line 5, the second
while loop (line 3) gets stuck at the first accurance of the pattern.
If I comment out line 5, I see that while loop iterates and the finds
the pattern as expected.

What am I missing here? Any suggestions?

Cheers,
hakan  

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

line 1 while (<WEBINP>){
line 2
line 3     while (m{(\D)(\d{4})(\D)}g){
line 4        $l = find($2,@list);
line 5        s/$2/$l/; } 
line 6
line 7     print WEBOUT $_;
line 8  }


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

Date: Tue, 16 Mar 2004 15:21:46 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: incrementing a string by a certain value
Message-Id: <pan.2004.03.16.14.20.31.67757@aursand.no>

On Tue, 16 Mar 2004 20:01:37 +1100, C3 wrote:
> How do I shift a string n letters up/down the alphabet?

What have you tried?  It's extremely easy if you stick to the ASCII table,
and my less than elegant example shows you why;

  my $string = 'ibm';
  my $offset = -1;

  foreach my $char ( split('', $string) ) {
      my $ord = ord($char) + $offset;
         $ord = ( $ord < 97  ) ? 122 : $ord;
         $ord = ( $ord > 122 ) ?  97 : $ord;
      print chr( $ord );
  }
  print "\n";


-- 
Tore Aursand <tore@aursand.no>
"I know not with what weapons World War 3 will be fought, but World War
 4 will be fought with sticks and stones." -- Albert Einstein


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

Date: Wed, 17 Mar 2004 01:30:26 +1100
From: "C3" <gned@telsmonopolytradotcom.remove.monopoly)>
Subject: Re: incrementing a string by a certain value
Message-Id: <40570f26$0$31903$afc38c87@news.optusnet.com.au>

I am fairly new to Perl. I'm used to doing this in C.

cheers,

C3

"Tore Aursand" <tore@aursand.no> wrote in message
news:pan.2004.03.16.14.20.31.67757@aursand.no...
> On Tue, 16 Mar 2004 20:01:37 +1100, C3 wrote:
> > How do I shift a string n letters up/down the alphabet?
>
> What have you tried?  It's extremely easy if you stick to the ASCII table,
> and my less than elegant example shows you why;
>
>   my $string = 'ibm';
>   my $offset = -1;
>
>   foreach my $char ( split('', $string) ) {
>       my $ord = ord($char) + $offset;
>          $ord = ( $ord < 97  ) ? 122 : $ord;
>          $ord = ( $ord > 122 ) ?  97 : $ord;
>       print chr( $ord );
>   }
>   print "\n";
>
>
> --
> Tore Aursand <tore@aursand.no>
> "I know not with what weapons World War 3 will be fought, but World War
>  4 will be fought with sticks and stones." -- Albert Einstein




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

Date: 16 Mar 2004 15:30:38 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: incrementing a string by a certain value
Message-Id: <slrnc5e7dp.t0p.roel-perl@localhost.localdomain>

On Tue, 16 Mar 2004 at 14:30 GMT, C3 wrote:
> I am fairly new to Perl. I'm used to doing this in C.

But this was an algorithm question, not specific to Perl. The
solutions shown to you could have been implemented in another
language. If you have questions about Perl, the best way is to
show us the code you have so far; we'll help you to improve it.


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

Date: 16 Mar 2004 05:58:00 -0800
From: rdb_spambucket@yahoo.co.uk (Roger Broadbent)
Subject: Problems installing IO::Tty locally
Message-Id: <3bb89e8c.0403160558.286e7595@posting.google.com>

Thanks in advance for looking at this. I've checked the FAQ and
perldoc.com and as far as I can see I'm following the instructions
there, but I can't create my own installation of IO::Tty. My goal is
to install Expect, and I've already successfully installed IO::Stty,
so I'm fairly sure I'm not making a very basic error.

I need to install locally as I don't have root access, and the system
admins won't be sympathetic to doing it for me.

The output is as follows. It looks like "make install" is trying to
install into the main Perl installation, despite my specifying my own
PREFIX when running Makefile.PL, as per the instructions in
perlmodinstall. I've taken a quick look at the generated makefile but
I haven't been able to correct it successfully.

This is what happens with the distribution as freshly downloaded from
CPAN (IO-Tty-0.04.tar.gz):

> make realclean
rm -rf Tty.c xssubs.c conf ./blib Makefile.aperl
blib/arch/auto/IO/Tty/extralibs.all perlmain.c mon.out core
so_locations pm_to_blib *~ */*~ */*/*~ *.o *.a perl.exe Tty.bs Tty.bso
Tty.def Tty.exp
mv Makefile Makefile.old > /dev/null 2>&1
rm -rf blib/lib/auto/IO/Tty blib/arch/auto/IO/Tty
rm -f blib/arch/auto/IO/Tty/Tty.so blib/arch/auto/IO/Tty/Tty.bs
rm -f blib/arch/auto/IO/Tty/Tty.a
rm -f blib/lib/IO/Pty.pm blib/lib/IO/Tty.pm
rm -rf Makefile Makefile.old
> perl Makefile.PL PREFIX=~/MyPerl
Looking for ttyname()....Found
Checking if your kit is complete...
Looks good
Writing Makefile for IO::Tty
> make 
mkdir blib
mkdir blib/lib
mkdir blib/lib/IO
mkdir blib/arch
mkdir blib/arch/auto
mkdir blib/arch/auto/IO
mkdir blib/arch/auto/IO/Tty
mkdir blib/lib/auto
mkdir blib/lib/auto/IO
mkdir blib/lib/auto/IO/Tty
mkdir blib/man3
cp Pty.pm blib/lib/IO/Pty.pm
cp Tty.pm blib/lib/IO/Tty.pm
/usr/bin/perl -I/usr/perl5/5.00503/sun4-solaris -I/usr/perl5/5.00503
/usr/perl5/5.00503/ExtUtils/xsubpp  -typemap
/usr/perl5/5.00503/ExtUtils/typemap Tty.xs >xstmp.c && mv xstmp.c
Tty.c
cc -c   -xO3 -xdepend     -DVERSION=\"0.04\"  -DXS_VERSION=\"0.04\"
-KPIC -I/usr/perl5/5.00503/sun4-solaris/CORE -DHAVE_DEV_PTMX
-DHAS_TTYNAME Tty.c
"Tty.xs", line 349: warning: assignment type mismatch:
        pointer to function() returning void "=" pointer to
function(int) returning int
"Tty.xs", line 354: warning: return value type mismatch
Running Mkbootstrap for IO::Tty ()
chmod 644 Tty.bs
LD_RUN_PATH="" cc -o blib/arch/auto/IO/Tty/Tty.so  -G Tty.o     
chmod 755 blib/arch/auto/IO/Tty/Tty.so
cp Tty.bs blib/arch/auto/IO/Tty/Tty.bs
chmod 644 blib/arch/auto/IO/Tty/Tty.bs
Manifying blib/man3/IO::Pty.3
> make install
Warning: You do not have permissions to install into
/usr/perl5/site_perl/5.005/sun4-solaris at
/usr/perl5/5.00503/ExtUtils/Install.pm line 61.
mkdir /usr/perl5/5.00503/man: Permission denied at
/usr/perl5/5.00503/ExtUtils/Install.pm line 57
*** Error code 2
make: Fatal error: Command failed for target `pure_site_install'
> perl -v

This is perl, version 5.005_03 built for sun4-solaris

Copyright 1987-1999, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5.0 source
kit.

Complete documentation for Perl, including FAQ lists, should be found
on
this system using `man perl' or `perldoc perl'.  If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.

> uname -imprsv
SunOS 5.8 Generic_108528-17 sun4u sparc SUNW,Sun-Fire-880

Thanks again,


Roger


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

Date: 16 Mar 2004 05:25:25 -0800
From: aclarke@austin.rr.com (ac)
Subject: Re: Regex to match simple line of XML
Message-Id: <ec432b9c.0403160525.7dec1188@posting.google.com>

(Tad, sorry it took a while to respond to this - I was annoyed because
my news reader lost my reply)

Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrnc54dlg.67f.tadmc@magna.augustmail.com>...
> ac <aclarke@austin.rr.com> wrote:
> 
> > I am trying to get a regex to match a simple line of XML.
> 
> 
> > my $xmlregex = qr/(?:^\s*<(\w+))|(?:\s+(\w)+=\"(.*?)\")|(?:>\s*$)/;
>                                          ^^^^^
> 
> 
> You only want the last letter of the attribute name?

Doh!

> (perhaps your test case should have included at least one attribute
>  with more than a 1-character name...)
> 
> Double quotes are not special, there is no need to backslash them.

I only escape them to keep my emacs syntax highlighter happy!

> > 	@items = ($line =~ m/$xmlregex/g);
> 
> 
> > I know that XML can be broken across lines, 
> 
> 
> And can use single quotes on attributes, and can have space characters
> that you don't account for and...
> 
> 
> > but this is just a special
> > case that I'm interested in. 
> 
> 
> Oh. OK then.
> 
> 
> > Note the blank lines (null entries) that came from the match. How do I
> > change the regex to avoid generating these null entries? 
> 
> 
> You can do it without changing the regex at all:
> 
>    @items = grep defined, $line =~ m/$xmlregex/g;
> 

I actually knew how to strip out the nulls, I was more interested in
why the regex was creating them in the first place.

> > I'm actually
> > trying to find the quickest way to parse that line of XML.
> 
> 
> I don't know how fast it is, but here is another way to try:
> 
>    if ( $testline =~ s/<([^>]+)>/$1/ ) {  # so long angle brackets
>       my @items =  grep length, split /\s+(\w+)="([^"]+)"/, $testline;
>       print "'$_'\n" for @items;
>    }

I tried this, but it was only marginally faster than the full regex I
was using. I guess I'm still at the following question:

Given a 200MB file composed of lines like the one below, what's the
fastest
way to parse it?

<row aaa="..." b="..." ...>

Allan


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

Date: 16 Mar 2004 11:12:54 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: system(...) does not produce output using 5.8.*
Message-Id: <slrnc5doaj.rts.roel-perl@localhost.localdomain>

On Tue, 16 Mar 2004 at 02:02 GMT, Manzoor Ilahi wrote:
> Hi
> 
> I have a program that contains the following code 
> 
> log_message("executing system($command)");
> return (system("$command") == 0);
                 ^^^^^^^^^^
(Don't use quotes on bare variable names.)
> 
> I run this on an NT machine using Cygwin.  Using Perl 5.6.1, I get the
> "$command"'s output on the screen.  But with Perl 5.8.* I do not see
> any output.

Are you sure $command still gets executed?


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

Date: Tue, 16 Mar 2004 14:41:19 +0000 (UTC)
From: Kees <witsuk@btopenworld.com>
Subject: Transparently Intercepting Mail
Message-Id: <c373mf$bo6$1@hercules.btinternet.com>

I am trying to write a little POP3 / SMTP proxy that will encrypt all 
email for the users (on a windows platform). This in itself is not very 
difficult. However it would be great if I could install this without 
having to change to settings on the users' email clients.

I know this should be possible (firewalls intercept all in and outgoing 
connections, I just want the pop and smtp ones), but I have no idea 
where to start. I think this is not really perl related, but I can't 
find any information on this and I don't know where else to start.

Any help, comments, pointers, links, etc are very welcome,

Thank you very much,

Kees


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

Date: 16 Mar 2004 12:42:50 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: variable initialization question
Message-Id: <u9oeqxm08l.fsf@wcl-l.bham.ac.uk>

ctcgag@hotmail.com writes:

> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> >  <ctcgag@hotmail.com> wrote in comp.lang.perl.misc:
> > >
> > > Let's say you are running an accumulator.  It is true that you don't
> > > get a warning upon incrementing an undef accumulator.  However, there
> > > is no point in having an accumulator which you don't use elsewhere, and
> > > when you do use it elsewhere you may find that it will emit errors on
> > > the boundary condition that the accumulator was incremented zero times.
> > > That's ugly and not particularly desirable.
> 
> > There are situations that demand initialization, and you have given
> > an example, but that's still a special case.
> 
> I understand people use Perl for all different kinds of things, and so
> will have differnt experiences, but from my experience if
> 1) the scalar variable is declared in the right scope, and
> 2) there is nothing substantial to initialize it to,
> then being an accumulator *is* the usual case, and it probably should
> be initialized to either 0 or '', depending on how it is used.
> 
> Plus, I like the clue that this gives about the variable's use ("hey, this
> is an accumulator, and a stringy one at that!")

I was going to put in my $0.02 worth in this thread then I found Xho
had made the point I was about to make.

I think most times we see "unecessary initialisation" we are usually
really seeing premature declaration.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 16 Mar 2004 14:47:42 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: variable initialization question
Message-Id: <x78yi0rgq9.fsf@mail.sysarch.com>

>>>>> "BM" == Brian McCauley <nobull@mail.com> writes:

  BM> I think most times we see "unecessary initialisation" we are usually
  BM> really seeing premature declaration.

please don't drag your personal health problems into this group.

:)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

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


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