[24345] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6534 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 7 06:05:59 2004

Date: Fri, 7 May 2004 03:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 7 May 2004     Volume: 10 Number: 6534

Today's topics:
        Array inside a hash <zturner_NOSPAM_0826@hotmail.com>
    Re: Array inside a hash (Sam Holden)
    Re: At wits end! LWP and IIS(?) <calvine@starhub.net.sg>
    Re: Books online???? (Anno Siegel)
    Re: Books online???? (taswold)
        Can someone check this bit of code please.? robert@chalmers.com.au
    Re: Can someone check this bit of code please.? <noreply@gunnar.cc>
    Re: Can someone check this bit of code please.? (Sam Holden)
    Re: Can someone check this bit of code please.? <robert@the.com>
        Concurrent processes (waiting for children) <lord-jacob@comcast.net>
    Re: Concurrent processes (waiting for children) (Sam Holden)
    Re: dclone and copying one element of a hash (TonyShirt)
    Re: free source authentication script <me@privacy.net>
    Re: hashes and array's <tore@aursand.no>
    Re: hashs and symbolic refrences (Sam Holden)
        How to redirect STDOUT to a string? <jkrugman@yahbitoo.com>
    Re: How to redirect STDOUT to a string? (Sam Holden)
    Re: How to redirect STDOUT to a string? <simon@unisolve.com.au>
    Re: How to redirect STDOUT to a string? <jwillmore@remove.adelphia.net>
    Re: How to redirect STDOUT to a string? <jwillmore@remove.adelphia.net>
    Re: Looking for a Expect like module <simon@unisolve.com.au>
        Open cdrom device on windows (manux)
    Re: Passing data from javascript to perl? (Bryan Castillo)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 07 May 2004 03:37:02 GMT
From: "Zachary Turner" <zturner_NOSPAM_0826@hotmail.com>
Subject: Array inside a hash
Message-Id: <yvDmc.68160$NR5.34376@fe1.texas.rr.com>

Say you've got a hash whose values are arrays (e.g. you just executed the
line of code $hash{"Blah} = ["a", "b"];).  How do you treat the array
without the compiler thinking you're talking about a hash slice?  Basically
I want to have some code that pushes certain things onto the end of such an
array, but when I call push, Perl thinks I'm referring to a hash slice so it
gives me an error.  The code in question is:

push(@hash{$c}, $a);




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

Date: 7 May 2004 04:01:17 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Array inside a hash
Message-Id: <slrnc9m2gd.avg.sholden@flexal.cs.usyd.edu.au>

On Fri, 07 May 2004 03:37:02 GMT,
	Zachary Turner <zturner_NOSPAM_0826@hotmail.com> wrote:
> Say you've got a hash whose values are arrays (e.g. you just executed the
> line of code $hash{"Blah} = ["a", "b"];).  How do you treat the array
> without the compiler thinking you're talking about a hash slice?  Basically
> I want to have some code that pushes certain things onto the end of such an
> array, but when I call push, Perl thinks I'm referring to a hash slice so it
> gives me an error.  The code in question is:
> 
> push(@hash{$c}, $a);

push @{$hash{$c}}, $a;

perldoc perlref :

    Anywhere you'd put an identifier (or chain of identifiers) as part of a
    variable or subroutine name, you can replace the identifier with a BLOCK
    returning a reference of the correct type. 

So we replace @NAME with @{$hash{$c}}.

You are allowed to read the documentation instead of guessing.

-- 
Sam Holden


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

Date: Fri, 7 May 2004 15:32:24 +0800
From: "Calvine Chew" <calvine@starhub.net.sg>
Subject: Re: At wits end! LWP and IIS(?)
Message-Id: <409b3ba3@news.starhub.net.sg>


"gnari" <gnari@simnet.is> wrote in message
news:c7e016$cdc$1@news.simnet.is...
> "Gisle Aas" <gisle@ActiveState.com> wrote in message
> news:m37jvqszkr.fsf@eik.g.aas.no...
> > "gnari" <gnari@simnet.is> writes:
> >
> > > I have never used these for file upload, and can't be bothered to do
> > > research, but I suspect that you at least need to specify
> > > multipart/form-data in the POST call, and probably some more
> > > work. an upload post is in a pretty different format that regular
> > > posts, and I am not sure HTTP::Request::Common supports it, thus the
> > > "501 (Not Implemented)" message.
> >
> > HTTP::Request::Common certainly do support file uploads.
>
> so it does!
>
> and after a quick look at the OP's code, I see that the filename
> passed to POST is not the same that was tested with -e.
> in addition, it looks to me that unsafe assumptions about current
> directory are made.
>
> gnari
>
Hi, apologies, the code I pasted is indeed wrong. However, I changed the
POST to reflect the correct variable, ie

my $fullpath = $ENV{'DOCUMENT_ROOT'}."/cgi-bin/$filename";
my $request=POST $url , Content_Type=>'form-data',
   Content => [upload=>[$fullpath]];
print $request->as_string; print;

But strangely enough, in the POST request headers, the field "upload" still
shows $filename, instead of $fullpath, in other words, LWP stripped off the
path...

Or did I do something wrong again?

Appreciate the help accorded!!




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

Date: 7 May 2004 09:14:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Books online????
Message-Id: <c7fk18$pag$1@mamenchi.zrz.TU-Berlin.DE>

taswold <hen_mcgiggle@yahoo.co.uk> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news: 
> 
> > When a posting annoys me, I reserve the right to reply in kind.  Why
> > should the wishes of the poster take precedence?
> 
> That depends on how easily annoyed you are, and how justified your
> annoyance.

You're not making sense.  We are talking about general rules of
conduct.  They can't depend on the individual, far less on the
individual case.

Your *assessment* of a situation may depend on all that, but that
is of little interest.

> People in the real world might expect you to keep your irritation to
> yourself for the general good.

The general good, eh?  Sure, we tend to forget that while we're
spending hours of spare time answering questions.  Thanks for
the reminder.

>                                Whereas I (after long lurking) expect
> you to pedantically reply to this with horribly specious arguments
> that I really hope you don't believe.

If you know the responses beforehand, why did you delurk?

> I *almost* sympathise with you about the trolls and the
> do-my-homeworks. You guys sometimes do some great things on here*.
> Unfortunately, you're also such a pompous bunch of nitwits.

Thanks.  Care to be specific?  Or does everyone become a pompous
nitwit, just by virtue of answering questions here?

> "RTFM"  IS rude and unhelpful, how in God's name can you seriously
> pretend otherwise?

Rude, yes.  Unhelpful, no.  Your skills of differentiation appear
to be lacking.

> I've read that nonsensical document (can't find the bookmark just now)

Then find it.  Vague reminiscences of something you have read somewhere
are of no interest.

[snip rest]

Anno


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

Date: 7 May 2004 02:32:00 -0700
From: hen_mcgiggle@yahoo.co.uk (taswold)
Subject: Re: Books online????
Message-Id: <288fb229.0405070132.7727c73f@posting.google.com>

Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote in message news:<87oep1fjfa.fsf@mithril.chromatico.net>...
> >>>>> "t" == taswold  <hen_mcgiggle@yahoo.co.uk> writes:
> 
>     t> "RTFM" IS rude and unhelpful, how in God's name can you
>     t> seriously pretend otherwise?
> 
> A flat "RTFM" is usually rude and unhelpful.  However, "RTFM -
> particularly perldoc -q 'my own module'" -- especially when the answer
> to the question is found in the FAQ, and it's clear that the querent
> hasn't read it -- is quite helpful.  What could *possibly* be gained
> by the respondent writing yet another response to the question instead
> of providing a pointer to the peer-reviewed answer in the FAQ or other
> documentation?

Seems sensible. I just wish we could take the "F" out. The pedantic,
sarcastic manner is a waste of time too, and that's absolutely rife on
c.l.p.misc.

tas


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

Date: Fri, 7 May 2004 01:32:56 GMT
From: robert@chalmers.com.au
Subject: Can someone check this bit of code please.?
Message-Id: <409ae748@dnews.tpgi.com.au>

This bit of code ..........

     36 if ($ENV{'QUERY_STRING'} ne '') {
     37    $buffer = "$ENV{'QUERY_STRING'}";}
     38
     39 else {
     40    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
     41   }

produces this error in response to the perl -w thing...

Use of uninitialized value in string ne at getmailwp.cgi line 36.
Use of uninitialized value in read at getmailwp.cgi line 40.

and I'm damed if I can find the problem ? No matter what I
declare/initialize what ever...

Thanks
Robert


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

Date: Fri, 07 May 2004 03:53:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Can someone check this bit of code please.?
Message-Id: <2g08qmF353t7U1@uni-berlin.de>

robert@chalmers.com.au wrote:
> This bit of code ..........
> 
>      36 if ($ENV{'QUERY_STRING'} ne '') {
>      37    $buffer = "$ENV{'QUERY_STRING'}";}
>      38
>      39 else {
>      40    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>      41   }
> 
> produces this error in response to the perl -w thing...
> 
> Use of uninitialized value in string ne at getmailwp.cgi line 36.
> Use of uninitialized value in read at getmailwp.cgi line 40.

The first warning means that $ENV{QUERY_STRING} is not defined, which 
indicates that you are running your CGI program from the command line.

The second warning means that $ENV{CONTENT_LENGTH} is not defined, 
which is the case as long as you don't invoke the script via a POST 
request.

> and I'm damed if I can find the problem ? No matter what I
> declare/initialize what ever...

Use CGI.pm.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 7 May 2004 02:04:47 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Can someone check this bit of code please.?
Message-Id: <slrnc9lrlv.lc.sholden@flexal.cs.usyd.edu.au>

On Fri, 7 May 2004 01:32:56 GMT,
	robert@chalmers.com.au <robert@chalmers.com.au> wrote:
> This bit of code ..........
> 
>      36 if ($ENV{'QUERY_STRING'} ne '') {
>      37    $buffer = "$ENV{'QUERY_STRING'}";}
>      38
>      39 else {
>      40    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>      41   }
> 
> produces this error in response to the perl -w thing...
> 
> Use of uninitialized value in string ne at getmailwp.cgi line 36.

$ENV{'QUERY_STRING'} is undef.

> Use of uninitialized value in read at getmailwp.cgi line 40.

$ENV{'CONTENT_LENGTH'} is undef.

> 
> and I'm damed if I can find the problem ? No matter what I
> declare/initialize what ever...

Why bother. CGI.pm does it all for you.

-- 
Sam Holden


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

Date: Fri, 7 May 2004 12:45:26 +1000
From: "Robert" <robert@the.com>
Subject: Re: Can someone check this bit of code please.?
Message-Id: <409af84a@dnews.tpgi.com.au>

ahhh, of course.

thank you.
Robert


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:2g08qmF353t7U1@uni-berlin.de...
> robert@chalmers.com.au wrote:
> > This bit of code ..........
> >
> >      36 if ($ENV{'QUERY_STRING'} ne '') {
> >      37    $buffer = "$ENV{'QUERY_STRING'}";}
> >      38
> >      39 else {
> >      40    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> >      41   }
> >
> > produces this error in response to the perl -w thing...
> >
> > Use of uninitialized value in string ne at getmailwp.cgi line 36.
> > Use of uninitialized value in read at getmailwp.cgi line 40.
>
> The first warning means that $ENV{QUERY_STRING} is not defined, which
> indicates that you are running your CGI program from the command line.
>
> The second warning means that $ENV{CONTENT_LENGTH} is not defined,
> which is the case as long as you don't invoke the script via a POST
> request.
>
> > and I'm damed if I can find the problem ? No matter what I
> > declare/initialize what ever...
>
> Use CGI.pm.
>
> -- 
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>




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

Date: Fri, 07 May 2004 07:08:51 GMT
From: Jacob Heider <lord-jacob@comcast.net>
Subject: Concurrent processes (waiting for children)
Message-Id: <6b0229d280ef62c66b56e7764e252aaf@news.teranews.com>

I've been following clpm for some months now, so hopefully I'll be able
to do this in a way that doesn't offend anyone.

I'm trying to write a console-based replacement for Grip, a
CD-ripper/-encoder under linux. In theory, I should be able to encode
the wav files while ripping subsequent once, since the actual CD-ripping
is IO-bound. The obvious way (to me, at least) is to fork a child to do
the encoding, and tell subsequent children not to start working until
prior children finish. (I think) I know why this doesn't work, i.e. the
first child isn't a child of the second child, etc., so waitpid won't
work. I know there got to be a better way, and probably at least a
half-dozen ways which could work. Please help.

The code (excerpt) which doesn't work is (some lines split to get under
72-characters):


#!/usr/bin/perl

use warnings;
use strict;

my $lastpid;

for (my $i = 1; $i <= 5; $i++) {
	
	system("cdda2wav -D /dev/cdrom -I cooked_ioctl -P 0 -t $i" 
               "-O wav -H -g $i.wav") == 0 
            or die "cdda2wav failed: $?\n";
	
	my $childpid = fork;
	die "fork failed: $?\n" unless defined($childpid);
	
	if ($childpid == 0) {
	
		if ($lastpid) {
			waitpid($lastpid, 0);
		}
	
		system("lame -V 3 $i.wav $i.mp3") == 0
                     or die "lame failed: $?\n";
		system("oggenc -q 3 -o $i.ogg $i.wav") == 0
                     or die "oggenc failed: $?\n";
		system("flac -6  -o $i.flac $i.wav") == 0
                     or die "flac failed: $?\n";

		system("rm $i.wav");
		
		exit;
		
	}
	
	$lastpid = $childpid;
}

__END__

The system calls could be anything, of course, but these are the
applications I'm calling. I have looked a Parallel::ForkManager, but
since this project is to get me into perl from a primarily C background,
I'm trying to be thorough in exploring my options.

Someday I hope to wrap this baby in a quality curses GUI (since I'm sick
to death of non-text apps), but if I can get the guts to run, I'll be
most of the way towards having something useful.

Thanks for the help,

Jacob


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

Date: 7 May 2004 07:55:16 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Concurrent processes (waiting for children)
Message-Id: <slrnc9mg73.1g6.sholden@flexal.cs.usyd.edu.au>

On Fri, 07 May 2004 07:08:51 GMT, Jacob Heider <lord-jacob@comcast.net> wrote:
> I've been following clpm for some months now, so hopefully I'll be able
> to do this in a way that doesn't offend anyone.
> 
> I'm trying to write a console-based replacement for Grip, a
> CD-ripper/-encoder under linux. In theory, I should be able to encode
> the wav files while ripping subsequent once, since the actual CD-ripping
> is IO-bound. The obvious way (to me, at least) is to fork a child to do
> the encoding, and tell subsequent children not to start working until
> prior children finish. (I think) I know why this doesn't work, i.e. the
> first child isn't a child of the second child, etc., so waitpid won't
> work. I know there got to be a better way, and probably at least a
> half-dozen ways which could work. Please help.

I'd approach it by forking a process that just keeps encoding
files until told to stop it would look something like:

#note: completely untested... not even executed once...

sub encode_files {
	while (my $file = <READER>) {
		chomp $file;
		system("lame -V 3 $file.wav $file.mp3") == 0
        		or die "lame failed: $?\n";
        	system("oggenc -q 3 -o $file.ogg $file.wav") == 0
        		or die "oggenc failed: $?\n";
        	system("flac -6  -o $file.flac $file.wav") == 0
        		or die "flac failed: $?\n";
	}
}

#create a pipe
pipe(READER,WRITER) or die "Unable to pipe: $!";
$| = 1, select $_ for select WRITER;

#fork a child and set it to work
my $childpid = fork();
die "fork failed: $?\n" unless defined($childpid);
if ($childpid == 0) {
	encode_files();
	exit(0);
}
 
for my $i (1 ... 5) {
	system("cdda2wav -D /dev/cdrom -I cooked_ioctl -P 0 -t $i" .
			"-O wav -H -g $i.wav") == 0
		or die "cdda2wav failed: $?\n";
	print WRITER "$i\n";
}
close WRITER;
wait();


Though I'd use the list form of system to stop the shell from
seeing the commands, and I'd pass an IO::Handle or a GLOB reference
to encode_files.
	
There might be blocking issues with the pipe, in which case you could 
use a temporary file, and treat a blank line as a terminate signal 
instead of eof.

I guess you could just open( WRITER, "|xargs [appropriate arguments")
where two of the appropriate arguments will be -l and -i instead of
the fork and child loop.

[snip code, most of which has been copied into the code above...]

-- 
Sam Holden


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

Date: 6 May 2004 20:39:54 -0700
From: tonyshirt@hotmail.com (TonyShirt)
Subject: Re: dclone and copying one element of a hash
Message-Id: <52d54c07.0405061939.78c3ff31@posting.google.com>

"A. Sinan Unur" <1usa@llenroc.ude> wrote in message news:<Xns94DEE0EBEBF6Fasu1cornelledu@132.236.56.8>...
> tonyshirt@hotmail.com (TonyShirt) wrote in 
> news:52d54c07.0405031747.26437a4a@posting.google.com:
> 
> > I've been using dclone to copy a hash to another hash.  At one point
> > in my program I need to copy one element of a hash into another.
> > 
> > Heres the code
> > 
> > my %a = { 1 => {a1=> 1, a2 =>2, a3=>3
> >        2 => {a1=> 4, a2 =>5, a3=>6};
> > 
> > my %b = %{ dclone(\%a) }
> > 
> > #now I want to clear %b and copy a element from a% into %b
> > 
> > my %b=();
> > 
> > $b{1} = dclone( $a{1});  # This dosent seem to work!
> > 
> > Any suggestions?
> 
> My first suggestion is not to re-type code into the newsreader. The code 
> you have above does not even come close to compiling without errors. So 
> nothing there works, it is hard to tell what the actual problem is versus 
> just your mis-mash.
> 
> How about the following?
> 
> use Data::Dumper;
> use Storable qw( dclone );
> 
> my $a = { 
>     1 => {
>         a1 => 1, 
>         a2 => 2, 
>         a3 => 3,
>     },
>     2 => { 
>         a1 => 4, 
>         a2 => 5,
>         a3 => 6,
>     },
> };
> 
> my $b = dclone( $a );
> 
> print Dumper $b;
> 
> $b = { };
> $b->{1} = dclone( $a->{1} );
> 
> print Dumper $b;
> __END__

Sorry -- I was just trying to simplify the analysis.  Next time I'll
provide all the code.  Thanks for the help it worked!

I have another question.  What is the diffence between Dumper $b and
Dumper %$b?  Why do they give diffrent results?


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

Date: Fri, 7 May 2004 21:18:44 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: free source authentication script
Message-Id: <2g12imF3b7ldU1@uni-berlin.de>


"Robin" <webmaster @ infusedlight . net> wrote in message
news:c7e9l0$72c$1@reader2.nmix.net...
> I might be an idiot, but not a stupid one.
> -Robin

May I have your permission to use that quote in my sig?




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

Date: Fri, 07 May 2004 11:15:34 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: hashes and array's
Message-Id: <pan.2004.05.07.09.15.18.267583@aursand.no>

On Thu, 06 May 2004 23:16:02 +0000, Dafke8 wrote:
>>> push @namen,$akte =~ m!<span\s+class="naam"\s+id="(n[0-9]+)">(.*?)</span>!g;

>>> if ( $akte =~ m!<span\s+class="naam"\s+id="n[0-9]+">(.*?)</span>!g ) {
>>>     push( @namen, $1 ,$2);
>>> }

> But will this work?

Which one of them?  Have you tried them both?  And - why don't you want to
see the difference? Let me ask you again:  What do you think gets pushed
to @namen if you use the first code above, and you regular expression
doesn't match?


-- 
Tore Aursand <tore@aursand.no>
"Nothing is certain but death and taxes. Of the two, taxes happen
 annually." (Joel Fox)


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

Date: 7 May 2004 01:44:03 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: hashs and symbolic refrences
Message-Id: <slrnc9lqf2.tcf.sholden@flexal.cs.usyd.edu.au>

On 6 May 2004 17:39:30 -0700, TonyShirt <tonyshirt@hotmail.com> wrote:
> I'm trying to parse a file with tag=value relationships.  The file
> looks something like this:
> 
> PRIMER_SEQUENCE_ID=1568502
> SEQUENCE=GAGCCCCCAGCCTCTGCACTTTCCACCAGCTCAGTCTCTAGGGCTTTATCTTTCTCTGTTCATTGTTACCCGTTGCCAGCTTTAGCTCAGTGTTGTGTGAGCCACACTTCTTCATCATTGAGGTGTTCCTGTTGTCAGTGGGCTAGCTAAGGGCAGAAGGGCATTCGTGGGATTTTAAAGAATTTATGGGACCAACATTCTTTCCGCCTTCAGCAGATACCGATTATGTTTCCAGGAGGTGGGATGTGCCAGAAGCCGTCACCTCTTTTTGTTTCTCCCCTGCCTGCCTTCTTTCTCTTTTCCTCTTTCTCAATAAACAGATACTGTCTGTGTGTCTGCCTCACCTAATCTAACCCTCAGATTGCAGACAGTGCTTTATTTAGACCCAAAG
> TTATGAGTCCTGATTGTGTTTTCCTGCTGGTCCCATCTGCTGTCTGTCTTTCAGTGGGCATCCACCGTTGTGGACCCAGGGATGGTTATGGGAAGCAAAACGTCTCCCTTAATCATAAACAGTGTCTACCAGTGGAAGCCCATCGACCGAGGGATCAGAGGCCTCTCAGTAGTATTGTTTATTGCAGTTCCTTGGCAACATTGCAGAGAGGCAGTCAGGTTCTGAAATACAACTGAGGTTATTGGCAGGCTGAGGCCCTGGCACAGGCACCTTCTAGAATATCAGCTAGTGTCTTGGCTTTCCTCTGGGGGGATCCCGTTGCTGTTGTGTTACAGAAATGGTAGTTGTTTACTCCAACAGTCTGGATGACCGCATAGAGGAACTATTTCARTAGTGACTG

[snip more of the same]

I don't see any handling of multi-line fields in the code you posted.

Or was that just usenet wrapping?

[snip more key=value lines]

[snip code]
> 
>             while(<IN>){
> 
>                 if ($_ =~ /(.+)=(.+)/){
> 
>                     $tag = $1;
>                     $value = $2;
>                 }
> 
>                 if ($tag eq "PRIMER_SEQUENCE_ID"){
>              
>                     $SeqID = $value;
>                 
>                 }elsif($SeqID ne ""){
> 
>                     $DataHash{$SeqID} = {$tag => $value}; #I think the
> problem is here!

That assigns a reference to a brand new hash containing just that one
key/value pair to $DataHash{$SeqID}, you want something like:

	$DataHash{$SeqID}{$tag} = $value;

To just add another key/value pair (and auto-vivify the hash reference the
first time through) to the existing hash.

[snip code]

> and I built a little Driver to test it:
> 
> #use strict;
> use diagnostics;
> use P3Wrapper;
> use Data::Dumper;
> 
> my $outputBIO = "Design_test/test3.P3OUT";
> 
> my $P3 = P3Wrapper->new("Design_test/");
> my ($rc,$msg,$Hash) = $P3 ->ParseBIO($outputBIO);
> 
> print Dumper $Hash;
> 
> The idea for the parser was that it didn't matter which tags were
> used,
> they were recorded in the hash with their values.  Notice the
> commented out pragma.
> I found that I was using symbolic references quite by accident, and I
> had to take out
> the strict pragma.  The problem is that I am capturing only one tag
> per key. see below.
> This is probably due the way I'm adding each tag to the hash (The
> problem comment).  I'm guessing, but I think
> I'm only getting the last tag in each sub hash because of the
> implementation of the symbolic references.
> Here is what I get when I run the driver:

There are no symbolic references that I can see. I ran the code with
use strict without any problems.

Other than handling those long lines (which is easy enough - when you see
a continuation line you add it to the last key you used, that requires
keeping track of the last key used, but that's no biggy, in fact your
code already does because $tag is scoped outside the loop). Speaking
of that you should scope things in the smallest scope they can be in,
you don't currently use $tag and $value outside the loop so they should
be myed inside the loop.


-- 
Sam Holden


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

Date: Fri, 7 May 2004 02:31:25 +0000 (UTC)
From: J Krugman <jkrugman@yahbitoo.com>
Subject: How to redirect STDOUT to a string?
Message-Id: <c7esdt$l8j$1@reader2.panix.com>



I'm using a module whose subs all write to STDOUT.  I want to
capture the output of these subs in a Perl string instead.  My
boneheaded (i.e. failed) attempt to solve this problem was:

  use IO::Scalar;
  my $string;
  *HOLD = *STDOUT;
  $STRING = IO::Scalar->new(\$string);
  *STDOUT = *STRING;
  foo(); # prints to STDOUT; output should be in $string  ???
  *STDOUT = *HOLD;

What's the correct way to do what I want to do?

Thanks!

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: 7 May 2004 03:20:17 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: How to redirect STDOUT to a string?
Message-Id: <slrnc9m03h.39j.sholden@flexal.cs.usyd.edu.au>

On Fri, 7 May 2004 02:31:25 +0000 (UTC),
	J Krugman <jkrugman@yahbitoo.com> wrote:
> 
> 
> I'm using a module whose subs all write to STDOUT.  I want to
> capture the output of these subs in a Perl string instead.  My
> boneheaded (i.e. failed) attempt to solve this problem was:
> 
>   use IO::Scalar;
>   my $string;
>   *HOLD = *STDOUT;
>   $STRING = IO::Scalar->new(\$string);
>   *STDOUT = *STRING;
>   foo(); # prints to STDOUT; output should be in $string  ???
>   *STDOUT = *HOLD;
> 
> What's the correct way to do what I want to do?

perldoc IO::Scalar :

	use IO::Scalar;
	### Writing to a scalar...
	my $s;
	tie *OUT, 'IO::Scalar', \$s;
	print OUT "line 1\nline 2\n", "line 3\n";
	print "String is now: $s\n"

So something like:

use IO::Scalar;
my $string;
tie *OUT, 'IO::Scalar', \$string;
*HOLD = *STDOUT;
*STDOUT = *OUT;
foo(); # prints to STDOUT; output should be in $string  ???
*STDOUT = *HOLD;

-- 
Sam Holden


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

Date: Fri, 07 May 2004 13:49:12 +1000
From: Simon Taylor <simon@unisolve.com.au>
Subject: Re: How to redirect STDOUT to a string?
Message-Id: <c7f14k$1od1$1@otis.netspace.net.au>

J Krugman wrote:
> I'm using a module whose subs all write to STDOUT.  I want to
> capture the output of these subs in a Perl string instead.  My
> boneheaded (i.e. failed) attempt to solve this problem was:
> 
>   use IO::Scalar;
>   my $string;
>   *HOLD = *STDOUT;
>   $STRING = IO::Scalar->new(\$string);
>   *STDOUT = *STRING;
>   foo(); # prints to STDOUT; output should be in $string  ???
>   *STDOUT = *HOLD;
> 
> What's the correct way to do what I want to do?

Hi Jill,

I've seen the Filter::Handle module used for this purpose, but I should
warn you that I couldn't get it to compile just now in my perl 5.8.3
Linux environment when I downloaded it from CPAN

In any event, it's probably worth a look.

Regards,

Simon
-- 
Unisolve Pty Ltd - Melbourne, Australia



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

Date: Fri, 07 May 2004 00:42:47 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: How to redirect STDOUT to a string?
Message-Id: <pan.2004.05.07.04.42.45.873806@remove.adelphia.net>

On Fri, 07 May 2004 02:31:25 +0000, J Krugman wrote:

> I'm using a module whose subs all write to STDOUT.  I want to capture
> the output of these subs in a Perl string instead.  My boneheaded (i.e.
> failed) attempt to solve this problem was:
> 
>   use IO::Scalar;
>   my $string;
>   *HOLD = *STDOUT;
>   $STRING = IO::Scalar->new(\$string);
>   *STDOUT = *STRING;
>   foo(); # prints to STDOUT; output should be in $string  ??? *STDOUT =
>   *HOLD;
> 
> What's the correct way to do what I want to do?

Try doing the following:

#duplicate STDOUT to a filehandle - so we can restore #STDOUT later
open(MYOUT, ">&STDOUT")
    or die "Can't dup STDOUT: $!\n";
#open a file to hold STDOUT
open(STDOUT, ">some_log_file")
    or die "Can't open STDOUT log file: $!\n";
#do some printing to STDOUT
print "STDOUT is now going into the log file\n"; 
 ...
#restore STDOUT
open(STDOUT, ">&MYOUT")
   or die "Can't restore STDOUT: $!\n";

The above code will work if you just want to redirect STDOUT to a file.
Simple, yet effective :-)

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 Hofstadter's Law:  It always takes longer than you expect, even 
 when you take Hofstadter's Law into account. 
 


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

Date: Fri, 07 May 2004 01:00:23 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: How to redirect STDOUT to a string?
Message-Id: <pan.2004.05.07.05.00.22.50517@remove.adelphia.net>

On Fri, 07 May 2004 00:42:47 -0400, James Willmore wrote:

> On Fri, 07 May 2004 02:31:25 +0000, J Krugman wrote:

>> I'm using a module whose subs all write to STDOUT.  I want to capture
>> the output of these subs in a Perl string instead.  My boneheaded (i.e.
>> failed) attempt to solve this problem was:
[ ... ]

>> What's the correct way to do what I want to do?
[ ... ]

> The above code will work if you just want to redirect STDOUT to a file.

My bad - you wanted a scalar and I gave a file :-(

Maybe you can use the code in the future :-)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 Blessed are they who Go Around in Circles, for they Shall be
 Known as Wheels. 
 


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

Date: Fri, 07 May 2004 13:15:16 +1000
From: Simon Taylor <simon@unisolve.com.au>
Subject: Re: Looking for a Expect like module
Message-Id: <c7ev4v$1nu2$1@otis.netspace.net.au>

Ash wrote:
> Hi,
> 
> Does anyone know of any other perl module than Expect.pm? I am writing a 
> script and within it need to log into another machine, perform a bunch 
> of commands and then get logout. Commonsense points to expect but I am 
> looking for a uncommonsense solution.
> 
> Help is appreciated in advance.


Assuming that you can telnet to the other machine, look at the 
Net::Telnet module.

Regards,

Simon Taylor
-- 
Unisolve Pty Ltd - Melbourne, Australia



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

Date: 7 May 2004 01:39:07 -0700
From: sirius-b@libero.it (manux)
Subject: Open cdrom device on windows
Message-Id: <97b3e53c.0405070039.50ae7588@posting.google.com>

Hi,

someone knows if there is a way to open the cdrom device on windows
with perl?
I found just about opening Serial ports (open P,"+>COM1") but nothing
about cdrom.
I tried to open /Devices/CdRom0,  \\.\CdRom0  but it doesn't work.

Thanks

manux

P.S. what I'd like to do is to burn an iso image on a cd-r and verify
md5sum (on linux I would open /dev/cdrom)


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

Date: 6 May 2004 20:34:12 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Passing data from javascript to perl?
Message-Id: <1bff1830.0405061934.5ea1123b@posting.google.com>

Bryan Coon <bcoon@sequenom.com> wrote in message news:<k8emc.60621$4o1.57902@newssvr25.news.prodigy.com>...
> Hi,
> 
> I have some perl scripts built which do pagination.  They just connect 
> to mysql and retrieve data sets using limit().  I have been informed by 
> the powers that be however that they want to have multiple selections 
> available -accross- pages.
> 
> I set up CGI::Session, and have built in the functionality to store the 
> id's of all items checked in the Session object, and to recheck items 
> that were previously checked.  The big problem is if a user deselects an 
> item.  How do I notify the perl script which item or items (there could 
> be a bunch per page) have been deselected????
> 
> At the end of the day, I need to have a perl array with the deselected 
> values in it, so I can compare it to the previously selected items 
> stored in their array in the Session object.  It would then be easy to 
> compare and remove the deselected items.
> 
> The only thing I can think of at the moment is some javascript array 
> that stuffs in the deselected id's, and then passes this array to the 
> perl cgi.  But there's no way I know of to pass a javascript array to 
> perl...
> 
> Anyone have any ideas?
> 

Here was another idea I had.
For every checkbox you have, also have a corresponding hidden field.
The checksboxes won't be returned if they are unchecked, but you will
know that the id was unchecked if the hidden field comes back but the
corresponding checkbox does not.

#!perl
use strict;
use warnings;
use CGI;
use File::Basename;

sub get_id_values {
  my ($cgi) = @_;
  my %ids;
  foreach my $k ($cgi->param()) {
    # the id was in the form
    if ($k =~ /^id_(\d+)$/) {
      $ids{$1} += 0;
    }
    # the id was checked in the form
    elsif ($k =~ /^id_(\d+)_cb$/) {
      $ids{$1} += 1;
    }
  }
  # this hash will have the id's as the keys
  # and a 1 or 0 for the value indicating if it was checked
  return \%ids;
}

my $script = basename($0);
my $cgi    = CGI->new;
my $ids    = get_id_values($cgi);

print <<END_HTML;
Content-type: text/html

<head>
<title>Test</title>
</head>
<body>
<form action="$script" method="POST">
<table>
END_HTML

foreach my $n (1..10) {
  print "<tr>",
        "<td>",
        "<input name='id_${n}' type='hidden' value='1'/>",
        "<input name='id_${n}_cb' type='checkbox'/>",
        "</td>",
        "<td>Item # $n</td>",
        "</tr>\n";
}

print <<END_HTML;
</table>
<input type="submit"/>
</form>
<hr/>
<table>
<tr><td>ID</td><td>CHECKED</td></tr>
END_HTML

foreach my $id (sort {$a <=> $b} keys %$ids) {
  my $checked = $ids->{$id};
  print "<tr><td>$id</td><td>$checked</td></tr>\n";
}


print <<END_HTML;
</body>
</html>
END_HTML



> B


-- 
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html


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

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


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