[28136] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9500 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 19 18:05:49 2006

Date: Wed, 19 Jul 2006 15:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 19 Jul 2006     Volume: 10 Number: 9500

Today's topics:
    Re: 2 Perl Software Engineers needed for great contract <dha@panix.com>
    Re: Help with script to get backup log status on window <benmorrow@tiscali.co.uk>
    Re: Help with tied/nested data structures xhoster@gmail.com
    Re: Help with tied/nested data structures <clint@0lsen.net>
    Re: Help with tied/nested data structures anno4000@radom.zrz.tu-berlin.de
    Re: Help with tied/nested data structures xhoster@gmail.com
    Re: Help with tied/nested data structures <mumia.w.18.spam+nospam.usenet@earthlink.net>
        how to alias an array with a variable in a loop ? <jack_posemsky@yahoo.com>
    Re: how to alias an array with a variable in a loop ? <David.Squire@no.spam.from.here.au>
    Re: how to alias an array with a variable in a loop ? <mritty@gmail.com>
    Re: how to alias an array with a variable in a loop ? <tzz@lifelogs.com>
    Re: how to alias an array with a variable in a loop ? <David.Squire@no.spam.from.here.au>
        How to substitute everything but something? Eric.Medlin@gmail.com
    Re: How to substitute everything but something? <mritty@gmail.com>
    Re: How to substitute everything but something? <tzz@lifelogs.com>
    Re: How to substitute everything but something? <someone@example.com>
    Re: How to substitute everything but something? <tzz@lifelogs.com>
    Re: How to substitute everything but something? <mritty@gmail.com>
    Re: How to substitute everything but something? <tzz@lifelogs.com>
    Re: How to substitute everything but something? <tzz@lifelogs.com>
    Re: How to use a module's @EXPORT array to document its anno4000@radom.zrz.tu-berlin.de
    Re: How to use a module's @EXPORT array to document its <1usa@llenroc.ude.invalid>
    Re: How to use a module's @EXPORT array to document its <news@lawshouse.org>
    Re: Premature end of script headers: mail.cgi <sherm@Sherm-Pendleys-Computer.local>
    Re: Premature end of script headers: mail.cgi <sherm@Sherm-Pendleys-Computer.local>
    Re: Premature end of script headers: mail.cgi <benmorrow@tiscali.co.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 Jul 2006 18:08:34 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: 2 Perl Software Engineers needed for great contract in NYC
Message-Id: <slrnebst92.90i.dha@panix2.panix.com>

On 2006-07-19, jessica.dwyer@scfoster.com <jessica.dwyer@scfoster.com> wrote:

> I have 2 Perl Software Engineer contract positions

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :)  (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here".  Just because one person jumps off a bridge, doesn't
mean everyone does.  Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
You kids today have it easy.  I remember when we had to write programs
with an ice pick and index cards.  <Note: This joke is not Y2k
compliant.  Soon people will ask, "What's an ice pick?"> - Lee Sharp


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

Date: Wed, 19 Jul 2006 20:28:46 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Help with script to get backup log status on windows systems
Message-Id: <eod2p3-fuk.ln1@osiris.mauzo.dyndns.org>


Quoth "Matt Williamson" <ih8spam@spamsux.org>:
> The purpose of this script is to quickly get a status on all of my nightly 
> backups. It's working for everything but the .xml backup files. There are 
> multiple .xml files created each night for the various processes that occur, 
> the actual backup log is only one of them. I've determined that the .xml 
> backup log files that I want are all encoded utf16le and the others are 
> utf8. I only want to read the utf16le .xml files and print the server name 
> and filename for just the latest of those but I can't figure out the best 
> way to do it. Also, if you have any suggestions on the script in general, 
> please feel free to comment. I'm new at this, so any advice from experienced 
> coders is welcome and appreciated.
> 
> use strict;
> use warnings;

Good :).

> my @content;

This variable is not needed at this scope. You should declare it inside
the first loop, as that's where you use it.

> my @header;

This variable is only needed per-file, so you should declare it
per-file. But see below for why I don't think you need it at all... :)

> my %belogdirs = (
>  "\\\\Server1"   => "\\d\$\\Backup Exec\\data\\bex*.txt",
>  \\\\Server2    => "\\c\$\\Program Files\\Seagate Software\\Backup 
> Exec\\Nt\\Data\\bex*.txt",
>  \\\\Server3    => "\\c\$\\Program Files\\Veritas\\Backup 
> Exec\\Nt\\Data\\bex*.txt",
>  \\\\Server4     => "\\c\$\\Program Files\\Veritas\\Backup 
> Exec\\Nt\\Data\\bex*.txt",
>  \\\\Server5     => "\\c\$\\Program Files\\Veritas\\Backup 
> Exec\\Nt\\Data\\bex*.txt",
>  \\\\Server6   => "\\c\$\\Program Files\\Veritas\\Backup 
> Exec\\Nt\\Data\\bex*.xml"
>  );

This would be easier with forward slashes and single quotes:

    '//Server1' => '/d$/Backup Exec/data/bex*.txt',

> open FILE, ">C:\\Backup Tape Log.txt";

It is generally safer to use lexical FHs and three-arg open, and you
should *always* check the return value:

    open my $FILE, '>', 'c:/Backup Tape Log.txt'
        or die "can't open 'c:/Backup Tape Log.txt': $!";

> foreach my $server (keys %belogdirs) {
>   my $fullpath = $server.$belogdirs{$server};
>   my @files = `dir "$fullpath" /OD /B`;

OK, now you'll hit the only snag of using forward slashes: cmd.exe and
most native NT commands don't like it :). You can either convert, with
either a simple s!/!\\!g or with File::Spec::Functions::canonpath, or
(probably better) you can use (I guess) glob to do the globbing in Perl.
(I'm not entirely sure glob will do what you want, as I don't know what
/OD /B means to dir, but you can certainly emulate it with either glob
or File::Find.)

>   foreach my $file (reverse @files) {
>     $fullpath =~ s/bex\*\.xml|bex\*\.txt/$file/i;
>     chomp $fullpath;

Ick. This will work, I guess, but it's pretty nasty. I think at this
point I'd do the whole thing a little differently, starting with a
datastructure more like

    my %belogdirs = (
        Server1 => {
            path  => 'd$/Backup Exec/data',
            extn  => 'txt',
        },
        ...
        Server6 => {
            dir   => 'c$/Program Files/Veritas/Backup Exec/Nt/Data',
            extn  => 'xml',
        },
    );

    for (keys %belogdirs) {
        my $glob = "//$_/$belogdirs{$_}{path}/bex*.$belogdirs{$_}{extn}";

Actually, although I normally hate it (in Perl), that would probably be
clearer as a sprintf:

        my $glob = sprintf '//%s/%s/bex*.%s' =>
            $_, $belogdirs{$_}{path}, $belogdirs{$_}{extn};

        for (reverse glob $glob) {
            open my $F, '<', $_ or die ...;

Note that glob returns full paths, rather than just a list of names.

>     open F, $fullpath or die "can't open $file: $!\n";
>     read F, my $buffer, 2;
>     @header = unpack "h*", $buffer;

Why are you using an array when you only have one return value?

>     close F;
> 
>  if ($header[0] =~ /ffef/i) { #handle the utf16 .xml files

You're not doing a pattern match here, you are checking for equality.
But you don't need to: if you can be sure your XML files will always
have a BOM, you can simply open the file :encoding(utf16). This will
throw an exception on the first read if there isn't a BOM. So,
continuing from the above:

        for my $file (reverse glob $glob) {
            my $mode;
            $belogdirs{$_}{extn} eq 'xml'
                and $mode = ':encoding(utf16)';
                
            # I don't really like file extensions, but if you've got
            # 'em you might as well use 'em...
        
            open my $F, "<$enc", $file
                or die "can't open '$file': $!";
                
            eval {
                @content = <$F>;
                1;
            } or next;
        }

This will skip onto the next file if the read throws an exception.

>       open F, "<:encoding(utf16le)", $fullpath or
>       die "can't open $file: $!\n";
>       @content = <F>;
>       close F;
>     }
>     elsif ($header[0] =~ /efff/i) { # just in case?
>       open F, "<:encoding(utf16be)", $fullpath or
>       die "can't open $file: $!\n";
>       @content = <F>;
>       close F;
>     }
>     else { # handle the .txt files
>   open F, $fullpath  or
>   die "can't open $file: $!\n";
>   @content = <F>;
>      close F;
>  }
> 
> #   $server =~ s/\\\\/Server: /;
> #   print FILE $server, "\n";
> #  print FILE "Log File: ",$fullpath,"\n";
> 
>    foreach my $line (@content){
>   if ($line =~ /(job (?:started|ended|completion status)):\s*(.*?)\s*$/i) {
>     my ($job_type, $status) = ($1, $2);
>     print FILE "$job_type: $status\n";

If you set $\ = "\n" then Perl'll print them for you.

>   }
>    }

It really helps a lot to keep you indentation sane.

>   print FILE "\n";
>   last;

I don't understand what this is here for?

>   }
> }
> 
> close FILE;
> exec("notepad C:\\Backup Tape Log.txt");

Does that work? It didn't ought to: the filename has spaces in it. I
would recommend using exec LIST so Perl does the nasty cmd.exe quoting
for you, even though it's not strictly as safe is it is on a real
platform:

    exec notepad => 'c:\\Backup Tape Log.txt';

I would also put this filename in a variable. Never write the same thing
twice.

Ben

-- 
                Outside of a dog, a book is a man's best friend.
                Inside of a dog, it's too dark to read.
benmorrow@tiscali.co.uk                                           Groucho Marx


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

Date: 19 Jul 2006 18:12:48 GMT
From: xhoster@gmail.com
Subject: Re: Help with tied/nested data structures
Message-Id: <20060719141805.689$9D@newsreader.com>

Clint Olsen <clint@0lsen.net> wrote:
> On 2006-07-19, anno4000@radom.zrz.tu-berlin.de
>
> I should point out that I have in the past been able to do nested tied
> structures and I didn't have problems with the Perl GC culling the
> objects.

You aren't having a problem with the GC culling them now.  If the GC simply
stopped culling them, then you would have a memory leak in addition to the
problem you are currently having.  It is merely a symptom, not the problem.

> I think this was around 5.6.X though...

I tested your program on 5.6.1, and it displayed the same problem as you
are seeing.  Maybe you did it in a different way back then?  You can do it
this way:

{
  my $x; tie $x, 'Bar', 'blah';
  $hash{bar}=\$x;
}

But then you need to dereference it upon use, which you might not like:

print "Tied scalar value is ${$hash{bar}}\n";

Maybe you could make an object with an overloaded stringifier?


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Wed, 19 Jul 2006 13:46:12 -0500
From: Clint Olsen <clint@0lsen.net>
Subject: Re: Help with tied/nested data structures
Message-Id: <slrnebsvfk.1cpj.clint@belle.0lsen.net>

On 2006-07-19, xhoster@gmail.com <xhoster@gmail.com> wrote:
> You aren't having a problem with the GC culling them now.  If the GC
> simply stopped culling them, then you would have a memory leak in
> addition to the problem you are currently having.  It is merely a
> symptom, not the problem.

Yes, you are right.

> I tested your program on 5.6.1, and it displayed the same problem as you
> are seeing.  Maybe you did it in a different way back then?  You can do
> it this way:

Yes, I was doing something entirely different.  I was chaining ties and
using Inline::C to link hashes of hashes of flubledorgs of arrays of... (ad
nauseum).  But the concept was the same.  HOWEVER, I never did ever try
tied scalars in the mix.  That could be where things are different.

> {
>   my $x; tie $x, 'Bar', 'blah';
>   $hash{bar}=\$x;
> }
>
> But then you need to dereference it upon use, which you might not like:
>
> print "Tied scalar value is ${$hash{bar}}\n";

Yeah, unfortunately we have a large and unwieldy codebase that's requiring
(or use'ing) this package, and we'd have to go update a lot of code to
derefence the scalar reference.  I like that you have found some
workaround, though.

> Maybe you could make an object with an overloaded stringifier?

Can you elaborate on this scheme?  I'm curious what this involves.

Thanks,

-Clint


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

Date: 19 Jul 2006 19:21:23 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Help with tied/nested data structures
Message-Id: <4i7f1jF2emblU1@news.dfncis.de>

 <xhoster@gmail.com> wrote in comp.lang.perl.misc:
> Clint Olsen <clint@0lsen.net> wrote:
> > On 2006-07-19, anno4000@radom.zrz.tu-berlin.de
> >
> > I should point out that I have in the past been able to do nested tied
> > structures and I didn't have problems with the Perl GC culling the
> > objects.
> 
> You aren't having a problem with the GC culling them now.  If the GC simply
> stopped culling them, then you would have a memory leak in addition to the
> problem you are currently having.  It is merely a symptom, not the problem.
> 
> > I think this was around 5.6.X though...
> 
> I tested your program on 5.6.1, and it displayed the same problem as you
> are seeing.  Maybe you did it in a different way back then?  You can do it
> this way:
> 
> {
>   my $x; tie $x, 'Bar', 'blah';
>   $hash{bar}=\$x;
> }
> 
> But then you need to dereference it upon use, which you might not like:
> 
> print "Tied scalar value is ${$hash{bar}}\n";
> 
> Maybe you could make an object with an overloaded stringifier?

Sounds like a possibility.

Here is another:  I'm assuming that the TieHash class actually
uses a normal hash to store values.  If it doesn't, your more
abstract approach may still work.  It still assumes that the
scalar is stored as such and not, for instance, stringified.
Some tie classes do that.

Say the "real" hash behind the tie is $obj->hashref.  Then add to
the methods in Tiehash one that returns a scalar ref to the relevant
hash location:

    sub location {
        my ( $obj, $key) = @_;
        \ $obj->hashref->{ $key};
    }

Then, after

    tie my %hash, 'TieHash';

instead of (vainly) trying to tie $hash{ $key}, do

    tie ${ tied( %hash)->location( $key) }, 'TieScalar';

This ties the place where $hash{ $key} is actually stored.  It
only makes sense when such a place exists.

Anno


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

Date: 19 Jul 2006 19:50:03 GMT
From: xhoster@gmail.com
Subject: Re: Help with tied/nested data structures
Message-Id: <20060719155522.013$iz@newsreader.com>

Clint Olsen <clint@0lsen.net> wrote:


> > You
> > can do it this way:
> > {
> >   my $x; tie $x, 'Bar', 'blah';
> >   $hash{bar}=\$x;
> > }
> >
> > But then you need to dereference it upon use, which you might not like:
> >
> > print "Tied scalar value is ${$hash{bar}}\n";
>
> Yeah, unfortunately we have a large and unwieldy codebase that's
> requiring (or use'ing) this package, and we'd have to go update a lot of
> code to derefence the scalar reference.  I like that you have found some
> workaround, though.

This may be getting into the "Cure is worse than disease" territory, but
you could change the tied hash so that it will automatically dereference
the thing when it gets fetched.  Of course, you need to do this automatic
derefernce only if the thing being fetched is actually a reference to a
tied variable.

# Fetch a value from a tied hash
#
sub FETCH {
    my $self = $_[0];
    my $key =  $_[1];
    print "FETCH(", ref $self, ") ", "$key => ",
                ${$self}{$key} ? ${$self}{$key} : "undef", "\n";
    return ${${$self}{$key}} if ref ${$self}{$key} eq 'SCALAR'
                                and tied ${${$self}{$key}};
    return ${$self}{$key};
}


Now you still need to store the reference:

{
my $x; tie $x, 'Bar', 'blah';
$hash{bar}=\$x;
}

But you no longer need to derefernce upon hash access:

print "Tied scalar value is $hash{bar}\n";

If the store is done in only a few tighly controlled places but the fetch
is done from many and/or uncontrolled places, this could work well.


>
> > Maybe you could make an object with an overloaded stringifier?
>
> Can you elaborate on this scheme?  I'm curious what this involves.

I haven't used overload, I just know about its existence, so I can't really
elaborate.  see perldoc overload.

The reason you have to store a reference to the tied scalar is that if you
try to store the tied scalar itself, it will invoke FETCH on it, rather
than storing the underlying SV.  By using overload rather than tie, you can
probably distinguish between "I'm fetching just to store it somewhere else"
vs "I'm fetching so that I can print out the contents".

However, if the codebase is unwieldy, then you probably can't gaurantee
that all of the "fetch to store" will be in a non-stringy context and all
of the "fetch to print" will be in the stringy context.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Wed, 19 Jul 2006 21:41:04 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Help with tied/nested data structures
Message-Id: <QFxvg.1976$bP5.853@newsread1.news.pas.earthlink.net>

On 07/19/2006 11:24 AM, xhoster@gmail.com wrote:
> "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:
>> One part of the problem is that you're not saving the values
>> returned by tie.
> 
> That is not the problem.
> [...]

You're right, it's not. Anno's description seems to be
correct. I can't find a way to tie a hash value to a class 
when the hash itself is also tied.

Unless Clint Olsen (the OP) wants to re-write Perl's
hash-tying code, it's probably better for him to re-write the
class he's tying the hash to.

Clint, I'm thinking that you can modify the hash-tying class 
(Foo) to accept a reference to an underlying hash and operate 
on the values in that hash. Then you can tie the scalars of 
the underlying hash to the scalar-tying class (Bar).


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

Date: 19 Jul 2006 13:17:27 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: how to alias an array with a variable in a loop ?
Message-Id: <1153340247.358720.262030@75g2000cwc.googlegroups.com>

Hi does anyone know how to do this ?

this works but its only 1 of my 377 chunkarrays !!  :
@chunkarray0 = sort {$a <=> $b} @chunkarray0;

this automation doesnt and I cant figure out why:
for ($t=0;$t<=$count;$t++) {
$chunkarray = 'chunkarray'.$t;
$cmd = '@'.$chunkarray.'= sort {$a <=>$b} @'.$chunkarray.';'; print
"COMMAND : ", $cmd."\n";
$cmd;
}

any tips GREATLY appreciated !



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

Date: Wed, 19 Jul 2006 21:27:26 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: how to alias an array with a variable in a loop ?
Message-Id: <e9m4je$n4f$1@gemini.csx.cam.ac.uk>

Jack wrote:
> Hi does anyone know how to do this ?
> 
> this works but its only 1 of my 377 chunkarrays !!  :
> @chunkarray0 = sort {$a <=> $b} @chunkarray0;
> 
> this automation doesnt and I cant figure out why:

Because you can't just plonk a variable down as a line of code and 
expect it to be interpreted as an instruction!

> for ($t=0;$t<=$count;$t++) {
> $chunkarray = 'chunkarray'.$t;
> $cmd = '@'.$chunkarray.'= sort {$a <=>$b} @'.$chunkarray.';'; print
> "COMMAND : ", $cmd."\n";
> $cmd;

Are you surprised that this didn't work???

> }
> 
> any tips GREATLY appreciated !
> 

I would do it with references, and most likely keep those references in 
a single overarching data structure (i.e. an array of array refs, or 
perhaps a hash of array refs). For example:


----

#!/usr/bin/perl
use strict;
use warnings;

my @array1 = qw( a d g s g s );
my @array2 = qw( sad ds fg sdf fg);
my @array3 = qw(  er rty tyr erw rty );

my @arrays = (\@array1, \@array2, \@array3);

foreach my $arrayref (@arrays) {
	my @sortedarray = sort {$a cmp $b} @$arrayref;
	print join ' ', @sortedarray;
	print "\n";
}

----


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

Date: 19 Jul 2006 13:33:22 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: how to alias an array with a variable in a loop ?
Message-Id: <1153341202.238732.183980@i42g2000cwa.googlegroups.com>

David Squire wrote:
> I would do it with references, and most likely keep those references in
> a single overarching data structure (i.e. an array of array refs, or
> perhaps a hash of array refs). For example:
>
>
> ----
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my @array1 = qw( a d g s g s );
> my @array2 = qw( sad ds fg sdf fg);
> my @array3 = qw(  er rty tyr erw rty );
>
> my @arrays = (\@array1, \@array2, \@array3);

Allow me to suggest that when you find yourself appending 1, 2, 3, etc
to the end of your variable names, stop what you're doing, erase it
all, and do it right from the outset.  Do not create three separate
arrays and then put references to them in a fourth big array.  Create
one array that contains references to anonymous arrays.  That way when
you need to edit your code later to add or remove an array, you only
have one change to make, not two:

my @arrays = (
  [ qw/a d g s g s/ ],
  [ qw/sad ds fg sdf fg/ ],
  [ qw/er rty tyr erw rty/ ],
);

> foreach my $arrayref (@arrays) {
> 	my @sortedarray = sort {$a cmp $b} @$arrayref;
> 	print join ' ', @sortedarray;
> 	print "\n";

Unless you've futzed with the $" variable, these last two lines are
more succinctly written:
print "@sortedarray\n";

> }

Paul Lalli



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

Date: Wed, 19 Jul 2006 16:36:36 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: how to alias an array with a variable in a loop ?
Message-Id: <g69fygxnxgr.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 19 Jul 2006, jack_posemsky@yahoo.com wrote:

> Hi does anyone know how to do this ?
>
> this works but its only 1 of my 377 chunkarrays !!  :
> @chunkarray0 = sort {$a <=> $b} @chunkarray0;
>
> this automation doesnt and I cant figure out why:
> for ($t=0;$t<=$count;$t++) {
> $chunkarray = 'chunkarray'.$t;
> $cmd = '@'.$chunkarray.'= sort {$a <=>$b} @'.$chunkarray.';'; print
> "COMMAND : ", $cmd."\n";
> $cmd;
> }

Put your @chunkarray0 ... @chunkarray377 variables in an array (let's
say it's called @caa).  You need to store references, not the
variables themselves.  Look at 'perldoc perldata' to learn about
Perl's built-in data types and what they can do for you.

Then iterate over the array (Data::Dumper will help you see the
structure of the example data I provided).

Ted


use Data::Dumper;

my @caa = ( [2,3,4,1,0], [10,14,12,9,4]);

foreach my $ca (@caa)
{
 @$ca = sort { $a <=> $b } @$ca;
}

print Dumper \@caa;



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

Date: Wed, 19 Jul 2006 21:42:49 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: how to alias an array with a variable in a loop ?
Message-Id: <e9m5g9$oju$1@gemini.csx.cam.ac.uk>

Paul Lalli wrote:
> David Squire wrote:
>> I would do it with references, and most likely keep those references in
>> a single overarching data structure (i.e. an array of array refs, or
>> perhaps a hash of array refs). For example:
>>
>>
>> ----
>>
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>>
>> my @array1 = qw( a d g s g s );
>> my @array2 = qw( sad ds fg sdf fg);
>> my @array3 = qw(  er rty tyr erw rty );
>>
>> my @arrays = (\@array1, \@array2, \@array3);
> 
> Allow me to suggest that when you find yourself appending 1, 2, 3, etc
> to the end of your variable names, stop what you're doing, erase it
> all, and do it right from the outset.  

I could not agree more. I was merely addressing the OPs actual problem 
statement.


DS


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

Date: 19 Jul 2006 11:32:57 -0700
From: Eric.Medlin@gmail.com
Subject: How to substitute everything but something?
Message-Id: <1153333977.154874.171820@i42g2000cwa.googlegroups.com>

I have $rawData[$i] =~ s/>.*<//;  That will replace everthing inside >
< include > and < with nothing.  But, I want to replace everthing but
what is inside > and <.  How can I negate what I have?



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

Date: 19 Jul 2006 11:38:54 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How to substitute everything but something?
Message-Id: <1153334334.567171.309900@m79g2000cwm.googlegroups.com>

Eric.Med...@gmail.com wrote:
> I have $rawData[$i] =~ s/>.*<//;  That will replace everthing inside >
> < include > and < with nothing.  But, I want to replace everthing but
> what is inside > and <.  How can I negate what I have?

TIMTOWTDI

$rawData[$i] =~ s/.*?(>.*<).*/$1/;

$rawData[$i] =~ /(>.*<)/ and $rawData[$i] = $1;

 ... and probably others.

Paul Lalli



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

Date: Wed, 19 Jul 2006 15:52:44 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to substitute everything but something?
Message-Id: <g69ejwhpe2b.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 19 Jul 2006, Eric.Medlin@gmail.com wrote:

> I have $rawData[$i] =~ s/>.*<//; That will replace everthing inside >
> < include > and < with nothing.  But, I want to replace everthing but
> what is inside > and <.  How can I negate what I have?

If you are trying to extract text from SGML/HTML/XML/etc. there are
easier ways.  The way you are attempting will not work in many common
cases.  See 'perldoc -q html' to get started.

In any case.  It may help to think of the problem as "extraction" of
what's between '>' and '<', rather than "elimination" of everything
except what's between those two delimiters.  I hope I understood your
request correctly.

You could do something like what's below.  Again, consider using a
parser specific to your data instead of grabbing text like this.

Ted

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

my $text = join '', <DATA>;
my @data = ($text =~ m/>(.*?)</g);
print Dumper \@data;
__DATA__
<html><head></head><body>HTML text here</body></html>
>just text here<
plain text here
<><><>text here<><


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

Date: Wed, 19 Jul 2006 19:55:05 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How to substitute everything but something?
Message-Id: <t6wvg.117204$I61.867@clgrps13>

Eric.Medlin@gmail.com wrote:
> I have $rawData[$i] =~ s/>.*<//;  That will replace everthing inside >
> < include > and < with nothing.  But, I want to replace everthing but
> what is inside > and <.  How can I negate what I have?

s/.*>//, s/<.*// for $rawData[ $i ];


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 19 Jul 2006 15:56:31 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to substitute everything but something?
Message-Id: <g69ac75pdw0.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 19 Jul 2006, mritty@gmail.com wrote:

Eric.Med...@gmail.com wrote:
>> I have $rawData[$i] =~ s/>.*<//; That will replace everthing inside >
>> < include > and < with nothing.  But, I want to replace everthing but
>> what is inside > and <.  How can I negate what I have?
>
> $rawData[$i] =~ /(>.*<)/ and $rawData[$i] = $1;

He asked for what's inside > <, so the above should be

$rawData[$i] =~ />(.*)</ and $rawData[$i] = $1;

Also, while the OP didn't specifically say it, he probably wants the
non-greedy match

$rawData[$i] =~ />(.*?)</ and $rawData[$i] = $1;

so the extracted data doesn't have < and > pairs inside it.

Ted


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

Date: 19 Jul 2006 13:03:54 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How to substitute everything but something?
Message-Id: <1153339434.156961.148610@m79g2000cwm.googlegroups.com>

Ted Zlatanov wrote:
> On 19 Jul 2006, mritty@gmail.com wrote:
>
> Eric.Med...@gmail.com wrote:
> >> I have $rawData[$i] =~ s/>.*<//; That will replace everthing inside >
> >> < include > and < with nothing.  But, I want to replace everthing but
> >> what is inside > and <.  How can I negate what I have?
> >
> > $rawData[$i] =~ /(>.*<)/ and $rawData[$i] = $1;
>
> He asked for what's inside > <, so the above should be
>
> $rawData[$i] =~ />(.*)</ and $rawData[$i] = $1;

He also said he wants to "negate what I have".  The two requirements
are contradictory, as what he has *does* replace > and <, so the
negation of that should *not* replace > and <.

I chose to abide by his final requirement.  You chose to abide by his
first.  Only the OP knows which one he meant.

> Also, while the OP didn't specifically say it, he probably wants the
> non-greedy match
>
> $rawData[$i] =~ />(.*?)</ and $rawData[$i] = $1;
>
> so the extracted data doesn't have < and > pairs inside it.

Now you're just being a mind reader.

Paul Lalli



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

Date: Wed, 19 Jul 2006 16:04:12 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to substitute everything but something?
Message-Id: <g6964htpdj7.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 19 Jul 2006, someone@example.com wrote:

Eric.Medlin@gmail.com wrote:
>> I have $rawData[$i] =~ s/>.*<//; That will replace everthing inside >
>> < include > and < with nothing.  But, I want to replace everthing but
>> what is inside > and <.  How can I negate what I have?
>
> s/.*>//, s/<.*// for $rawData[ $i ];

I think the OP's code will match the biggest >xyz< pair, while your
code will extract the last >xyz< pair.  My followup will extract all
the >xyz< data.  I don't think the problem as specified can be solved
exactly right, so maybe the OP should help us a little :)

Ted


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

Date: Wed, 19 Jul 2006 16:10:50 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to substitute everything but something?
Message-Id: <g691wshpd85.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 19 Jul 2006, mritty@gmail.com wrote:

Ted Zlatanov wrote: > On 19 Jul 2006, mritty@gmail.com wrote: > > Eric.Med...@gmail.com wrote:
>>>> I have $rawData[$i] =~ s/>.*<//; That will replace everthing inside >
>>>> < include > and < with nothing.  But, I want to replace everthing but
>>>> what is inside > and <.  How can I negate what I have?
>>>
>>> $rawData[$i] =~ /(>.*<)/ and $rawData[$i] = $1;
>>
>> He asked for what's inside > <, so the above should be
>>
>> $rawData[$i] =~ />(.*)</ and $rawData[$i] = $1;
>
> He also said he wants to "negate what I have".  The two requirements
> are contradictory, as what he has *does* replace > and <, so the
> negation of that should *not* replace > and <.
>
> I chose to abide by his final requirement.  You chose to abide by his
> first.  Only the OP knows which one he meant.

Yeah, see my followup to John Krahn, we don't really know what the
requirements are.  I didn't read the last requirement the way you did,
obviously.

>> Also, while the OP didn't specifically say it, he probably wants the
>> non-greedy match
>>
>> $rawData[$i] =~ />(.*?)</ and $rawData[$i] = $1;
>>
>> so the extracted data doesn't have < and > pairs inside it.
>
> Now you're just being a mind reader.

Er, you can certainly interpret it that way :)  I read

"everything but what is inside > and <"

as "the first < should terminate 'what is inside'".  Confusing
requirements breed confusion, I guess.  Sorry for that, as I
perpetuated the confusion.

Ted


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

Date: 19 Jul 2006 19:35:22 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: How to use a module's @EXPORT array to document its exported objects?
Message-Id: <4i7frqF2he80U1@news.dfncis.de>

Henry Law  <news@lawshouse.org> wrote in comp.lang.perl.misc:

> ...expanded considerably, and I'm still developing, so I'm trying to 
> develop a simple utility which will document which objects are exported 
> from each module, and its version.

[...]

> Here's the core of my code, using a standard module so you can run it if 
> you need to:
> 
> #! /usr/bin/perl
> use strict; use warnings;
> require File::Copy;
> foreach my $exported_sub (@File::Copy::EXPORT_OK) {
> 	print "$exported_sub\n";
> }
> 
> For this particular module it works fine:
> 
> > F:\>tryit.pl
> > cp
> > mv
> 
> But if I run it on my Windows _development_ _client_ against one of the 
> _server_ modules the "require" statement croaks because the server has a 
> different set of Perl modules installed.  I get "Can't locate xxx in 
> @INC (@INC contains ..." messages.
> 
> So can I get access to the @EXPORT variables from a module without 
> causing the "require" statement to fail because it can't load dependent 
> modules?   Or can I suppress the "Can't locate" messages safely just for 
> the tool?

The latter.  perldoc -f eval.

Anno


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

Date: Wed, 19 Jul 2006 21:54:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to use a module's @EXPORT array to document its exported objects?
Message-Id: <Xns9805B636D3E67asu1cornelledu@127.0.0.1>

Henry Law <news@lawshouse.org> wrote in news:1153327933.17726.0
@proxy00.news.clara.net:

> But if I run it on my Windows _development_ _client_ against one of
> the  _server_ modules the "require" statement croaks because the
> server has a  different set of Perl modules installed.  I get "Can't 
> locate xxx in @INC (@INC contains ..." messages.
> 
> So can I get access to the @EXPORT variables from a module without 
> causing the "require" statement to fail because it can't load 
> dependent modules?

 ...

> I realise that I could work around the problem

 ...

> by installing the server modules on the client where I'm running the 
> documentation tool. 

 ...

> ugly and maybe not even possible.

I do not understand why that is ugly or impossible in most cases. It 
seems to me that the development environment ought to be as similar to 
the deployment environment as possible.

On the other hand, I just went to search.cpan.org, and typed:

module info 

in the search box.

Among the results, there were some promising looking modules, but I 
would not a priori expect them to deliver exactly the information you 
need without being able to compile a module.

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://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Wed, 19 Jul 2006 21:52:49 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: How to use a module's @EXPORT array to document its exported objects?
Message-Id: <1153342368.96442.0@iris.uk.clara.net>

anno4000@radom.zrz.tu-berlin.de wrote:
> Henry Law  <news@lawshouse.org> wrote in comp.lang.perl.misc:
 ...
>> But if I run it on my Windows _development_ _client_ against one of the 
>> _server_ modules the "require" statement croaks because the server has a 
>> different set of Perl modules installed.  I get "Can't locate xxx in 
>> @INC (@INC contains ..." messages.
 ...
>> modules?   Or can I suppress the "Can't locate" messages safely just for 
>> the tool?
> 
> The latter.  perldoc -f eval.

OK, I see the basic principle: wrap up my "require" in an eval statement 
so that the program doesn't crash.  But the eval still fails with the 
same error (now visible in $@), and doesn't create the variables, or 
make them visible.

Snippet of the code
eval {require NFB::Utilities::Server};
warn $@ if $@;
print "Version of NFB::Utilities::Server is 
$NFB::Utilities::Server::VERSION\n";

The variable $NFB::Utilities::Server::VERSION (which I can see is 
defined in the module) is undefined, as is the @EXPORT_OK array etc.

I must be missing something ...


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

Date: Wed, 19 Jul 2006 16:17:42 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Premature end of script headers: mail.cgi
Message-Id: <m2y7up4ae1.fsf@Sherm-Pendleys-Computer.local>

"Paul Lalli" <mritty@gmail.com> writes:

> Pare your problem down, removing all the code that's not
> relevant to the error until you get the shortest possible complete
> script that still generates the error.  This is an imporant part of
> debugging, and something you should be doing whenever you can't figure
> out why your program doesn't work.

It's also worth pointing out that at least nine times out of ten, this
process will lead you to finding your own solution without having to post
a question here at all.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Wed, 19 Jul 2006 16:23:54 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Premature end of script headers: mail.cgi
Message-Id: <m2u05d4a3p.fsf@Sherm-Pendleys-Computer.local>

usenet@DavidFilmer.com writes:

> FWIW, the mesage you are seeing ("premature end...") is
> characteristicly displayed in a browser when a  CGI program is invoked
> but the program fails because of a syntax or runtime error. The script
> generates error messages (or maybe nothing at all), but the browser is
> expecting a proper HTML page with (at least) a proper HTML header.

That's completely wrong.

The "Premature end..." error is generated by the *server*, not the browser,
and it's generated when a script exits without creating a valid set of HTTP
(not HTML) headers.

> When the CGI program exits without providing the browser some valid
> HTML, the browser complains.

The browser is not complaining at all - all it's doing is displaying the
complaint that the server returned. Don't shoot the messenger. :-)

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Wed, 19 Jul 2006 21:34:01 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Premature end of script headers: mail.cgi
Message-Id: <pih2p3-l8l.ln1@osiris.mauzo.dyndns.org>


Quoth Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>:
> usenet@DavidFilmer.com writes:
> 
> The "Premature end..." error is generated by the *server*, not the browser,
> and it's generated when a script exits without creating a valid set of HTTP
> (not HTML) headers.

Pick pick...

CGI (not HTTP) headers. They differ in some important respects (notably,
ending with "\n" rather than "\cM\cJ").

Ben

-- 
For far more marvellous is the truth than any artists of the past imagined!
Why do the poets of the present not speak of it? What men are poets who can
speak of Jupiter if he were like a man, but if he is an immense spinning
sphere of methane and ammonia must be silent?~Feynmann~benmorrow@tiscali.co.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:

#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 9500
***************************************


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