[18192] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 360 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 26 18:10:50 2001

Date: Mon, 26 Feb 2001 15:10:22 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983229022-v10-i360@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 26 Feb 2001     Volume: 10 Number: 360

Today's topics:
        Please Help with 10 line programm -- beginner questions <mshort@usol.com>
    Re: Please Help with 10 line programm -- beginner quest (John Joseph Trammell)
    Re: Please Help with 10 line programm -- beginner quest (Randal L. Schwartz)
    Re: Please Help with 10 line programm -- beginner quest <shanem@ll.mit.edu>
    Re: Please Help with 10 line programm -- beginner quest (Randal L. Schwartz)
    Re: Please Help with 10 line programm -- beginner quest <shanem@ll.mit.edu>
    Re: Please Help with 10 line programm -- beginner quest <thoren@southern-division.com>
        Problem wit ActiveState on NT IPC(pipes) and fork <melon_medley@latitude48north.com>
    Re: Problem wit ActiveState on NT IPC(pipes) and fork <cadet@alum.mit.edu>
    Re: question about 'for' loop functionality <bernie@fantasyfarm.com>
    Re: question about 'for' loop functionality <bart.lateur@skynet.be>
    Re: question on how to code a program (Abigail)
    Re: Re: cgi-bin not excuting perl scripts. what have i  <abcd@ntlworld.com>
        receiving piped input??? <lanaS55nospam@hotmail.com>
    Re: receiving piped input??? (Anno Siegel)
    Re: receiving piped input??? <maheshasolkar@yahoo.com>
    Re: receiving piped input??? (Tim Hammerquist)
    Re: RFD - comp.lang.perl.db, comp.lang.perl.network, co (Abigail)
        shell script to perl (NEWBIE) <shino_korah@yahoo.com>
        Simple question about change of base (James Weisberg)
    Re: Simple question about change of base (James Weisberg)
    Re: Simple question about change of base <maheshasolkar@yahoo.com>
    Re: Simple question about change of base <maheshasolkar@yahoo.com>
    Re: Simple question about change of base <iltzu@sci.invalid>
    Re: Simple question about change of base (John Joseph Trammell)
    Re: Simple question about change of base (Craig Berry)
    Re: simple question on array splice hack <cadet@alum.mit.edu>
        SSL tunneling <bruno.dewolf@eozen.com>
        Would the Net::FTP and LWP modules cope in an industria <abcd@ntlworld.com>
    Re: Would the Net::FTP and LWP modules cope in an indus blah@blah.blah.invalid
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 26 Feb 2001 13:04:00 -0800
From: "mshort" <mshort@usol.com>
Subject: Please Help with 10 line programm -- beginner questions
Message-Id: <t9l6do903t6tb5@corp.supernews.com>

The assignment in the book is to modify this program:


print 'Would you like to see the 11:00 show of Cape Fear?';
chomp($ans=<>);
if ($ans eq 'yes'){
    print "that'll be 8.50\n";
    } elsif ($ans eq 'no'){
    print "Okay\n";
    } else {print "please try again\n";
    }

With a WHILE loop.

I have tried several variations and this is the best one I come up with, but
it has a problem:

while ($ans ne 'yes', $ans ne 'no'){
    print 'Would you like to see the 11 show of Cape Fear?';
chomp($ans=<>);
if ($ans eq 'yes'){
    print "that'll be 8.50\n";
    } elsif ($ans eq 'no'){
    print "Okay\n";
    } else {
    print "please try again\n";
    }
}

It won't exit upon $ans eq 'yes'.  I am figuring in the condition of the
WHILE statement is where my problem lies.  I know there must be a way for
WHILE to loop if $ans is not equal to yes AND no.  And I think I can use 2
while loops one for each yes and no, but I am hoping there is a more
efficient way.


Sincerely,

Matt Short





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

Date: Mon, 26 Feb 2001 18:10:36 GMT
From: trammell@bayazid.hypersloth.net (John Joseph Trammell)
Subject: Re: Please Help with 10 line programm -- beginner questions
Message-Id: <slrn99l4rf.r0q.trammell@bayazid.hypersloth.net>

On Mon, 26 Feb 2001 13:04:00 -0800, mshort <mshort@usol.com> wrote:
> while ($ans ne 'yes', $ans ne 'no'){

What test are you trying to perform here?  Maybe you should
do some experimenting with this.

And you're "using strict", right?



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

Date: 26 Feb 2001 10:14:54 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Please Help with 10 line programm -- beginner questions
Message-Id: <m1n1b9e2g1.fsf@halfdome.holdit.com>

>>>>> "mshort" == mshort  <mshort@usol.com> writes:

mshort> It won't exit upon $ans eq 'yes'.  I am figuring in the
mshort> condition of the WHILE statement is where my problem lies.  I
mshort> know there must be a way for WHILE to loop if $ans is not
mshort> equal to yes AND no.  And I think I can use 2 while loops one
mshort> for each yes and no, but I am hoping there is a more efficient
mshort> way.

How about putting that "and" word in there?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 26 Feb 2001 14:19:42 -0500
From: Shane McDaniel <shanem@ll.mit.edu>
Subject: Re: Please Help with 10 line programm -- beginner questions
Message-Id: <3A9AAC4E.C930F70F@ll.mit.edu>

I believe the first line of the while should be 

while (($ans ne 'yes') && ($ans ne 'no')){

Does anyone know what using a ',' in the while does exactly?


mshort wrote:
> 
> The assignment in the book is to modify this program:
> 
> print 'Would you like to see the 11:00 show of Cape Fear?';
> chomp($ans=<>);
> if ($ans eq 'yes'){
>     print "that'll be 8.50\n";
>     } elsif ($ans eq 'no'){
>     print "Okay\n";
>     } else {print "please try again\n";
>     }
> 
> With a WHILE loop.
> 
> I have tried several variations and this is the best one I come up with, but
> it has a problem:
> 
> while ($ans ne 'yes', $ans ne 'no'){
>     print 'Would you like to see the 11 show of Cape Fear?';
> chomp($ans=<>);
> if ($ans eq 'yes'){
>     print "that'll be 8.50\n";
>     } elsif ($ans eq 'no'){
>     print "Okay\n";
>     } else {
>     print "please try again\n";
>     }
> }
> 
> It won't exit upon $ans eq 'yes'.  I am figuring in the condition of the
> WHILE statement is where my problem lies.  I know there must be a way for
> WHILE to loop if $ans is not equal to yes AND no.  And I think I can use 2
> while loops one for each yes and no, but I am hoping there is a more
> efficient way.
> 
> Sincerely,
> 
> Matt Short


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

Date: 26 Feb 2001 11:54:13 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Please Help with 10 line programm -- beginner questions
Message-Id: <m1lmqtcja2.fsf@halfdome.holdit.com>

>>>>> "Shane" == Shane McDaniel <shanem@ll.mit.edu> writes:

Shane> Does anyone know what using a ',' in the while does exactly?

Well, let's work it through.

"while" is looking for a boolean.

a boolean is always a scalar.

so the expression is being evaluated in a scalar context.

the "," in a scalar context is the "comma operator", which evaluates
its left argument (in a scalar context), throws it away, then
evaluates and returns its right argument (in a scalar context).

So, you were evaluating $ans ne 'yes', throwing that away, then
evaluating and using $ans ne 'no' as your deciding expression.

Not very useful. :)

But perfectly legal code, even if unusual.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 26 Feb 2001 16:38:25 -0500
From: Shane McDaniel <shanem@ll.mit.edu>
Subject: Re: Please Help with 10 line programm -- beginner questions
Message-Id: <3A9ACCD1.C1DEA364@ll.mit.edu>

Cool.  It's points like these that I like to tell people that "Every
programming language will let you shoot yourself in the foot, however
with perl you're using an automatic."

"Randal L. Schwartz" wrote:
> 
> >>>>> "Shane" == Shane McDaniel <shanem@ll.mit.edu> writes:
> 
> Shane> Does anyone know what using a ',' in the while does exactly?
> 
> Well, let's work it through.
> 
> "while" is looking for a boolean.
> 
> a boolean is always a scalar.
> 
> so the expression is being evaluated in a scalar context.
> 
> the "," in a scalar context is the "comma operator", which evaluates
> its left argument (in a scalar context), throws it away, then
> evaluates and returns its right argument (in a scalar context).
> 
> So, you were evaluating $ans ne 'yes', throwing that away, then
> evaluating and using $ans ne 'no' as your deciding expression.
> 
> Not very useful. :)
> 
> But perfectly legal code, even if unusual.
> 
> print "Just another Perl hacker,"
> 
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 26 Feb 2001 22:48:15 +0100
From: Thoren Johne <thoren@southern-division.com>
Subject: Re: Please Help with 10 line programm -- beginner questions
Message-Id: <MPG.1504ed8a8347672b9898be@news.btx.dtag.de>

In article <3A9ACCD1.C1DEA364@ll.mit.edu>, Shane McDaniel aka 
shanem@ll.mit.edu says...

> Cool.  It's points like these that I like to tell people that "Every
> programming language will let you shoot yourself in the foot, however
> with perl you're using an automatic."

yeah - and logo is no shooting, but bondage ;)

-- 
# Thoren Johne - 8#X - thoren@southern-division.com
# Southern Division Classic Bikes - www.southern-division.com
*human=*you=*me=*stupid=*DATA=>#print"Just Another Perl Hacker\n     8#X"
*stupid&&*human&&*me&&*you&&2&&seek*me,-118,1;read*you,$_,42;eval;__END__


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

Date: Mon, 26 Feb 2001 08:56:04 -0800
From: "JonK" <melon_medley@latitude48north.com>
Subject: Problem wit ActiveState on NT IPC(pipes) and fork
Message-Id: <97e1ul$844$1@barad-dur.nas.com>

Hello,

I am trying to port some UNIX perl code (code snippet below) to WinNT
4.0 running the lastest version of ActiveState Perl.   The code
section that I am having problems with is forking children to perform
reverse DNS lookups and using pipes for the IPC.  (The code
originally used socketpair(), but this appearently is not implemented
on ActiveStates WinNT Perl so I rewrote it use pipes. ) The code
works fine on Unix but hangs on WinNT.  The debugger is somewhat
useless, but I believe that the select call is returning and there
are no descripters in the returned array.

Does anyone have experice with pipes and fork on WinNT? (or any
alternative bidirectional IPC mechanism on WinNT!)

#!/usr/bin/perl

use strict;
use Socket;
use IO::Handle;
use IO::Select;

use vars qw(%Buffer  %Cache $write_select $read_select );
use vars qw($Next_Line %Swap_fh);
use vars qw($CHILDREN $TIMEOUT $FLUSH $DEBUG);
$CHILDREN = 1;                          # Number of children to spawn
$TIMEOUT  = 30;                         # DNS timeout
$FLUSH    = 3000;                       # Flush buffer every $FLUSH
lines


&spawn_children;

&host_lookup;
print "\nALL DONE\n";
exit(1);

sub host_lookup {

    my $logfile = "access_log";

    $Next_Line = 1;
    my $lineno = 0;
    my %pending = ();
    my $eof = 0;

    open (RAWLOG, "<$logfile")
      or die "$0: cannot open";
    my $infile = \*RAWLOG;

    while(1) {

        my ($readable, $writable) =
          IO::Select->select ($read_select, $write_select, undef);

        if (@$writable) {
            # One or more children ready for an IP
            my $line = '';
            while (@$writable and defined($line = <$infile>)) {
                my ($ip, $rest) =  split (/ +/, $line, 2);
                &flush_buffer () if ++$lineno % $FLUSH == 0;
                if (exists $Cache{$ip}) {
                    # We found this answer already
                    $Buffer{$lineno} = "$Cache{$ip} $rest";
                }
                elsif (exists $pending{$ip}) {
                    # We're still looking
                    push @{ $pending{$ip} }, [ $lineno, $rest ];
                }
                else {
                    # Send IP to child
                    my $write_fh = shift @$writable;
                    print $write_fh "$ip\n";
                    $pending{$ip} = [ [ $lineno, $rest ] ];
                    $write_select->remove ($write_fh); # Move to read
set
                    $read_select->add ($Swap_fh{$write_fh});
                }
            }
            # Are we done with input?
            $eof = ! defined $line;
        }

        while (@$readable) {
            # One or more children have an answer
            my $read_fh = shift @$readable;
            my $str = <$read_fh>;
            chomp ($str);
            my ($ip, $host) = split / /, $str, 2;
            $Cache{$ip} = $host;

            # Take all the lines that were pending for this IP and
            # toss them into the output buffer
            my $pending;
            foreach $pending (@{ $pending{$ip} }) {
                $Buffer{$pending->[0]} = "$host $pending->[1]";
            }
            delete $pending{ $ip };

            # Move to write set
            $read_select->remove ($read_fh);
            $write_select->add ($Swap_fh{$read_fh});
        }

        last if $eof and not keys %pending;
    }

    &flush_buffer ();
}

# Write as many lines as we can until we come across one
# that's missing (that means it's still pending DNS).
sub flush_buffer {
    my $i;

    for (; exists $Buffer{$Next_Line}; $Next_Line++) {
        $_ = delete $Buffer{$Next_Line};
        print  $_;
    }
}

sub spawn_children {
   # Spawn the children
   $read_select  = new IO::Select;
   $write_select = new IO::Select;

   my $child;
   for($child = 1; $child <= $CHILDREN; $child++) {
      my($parent_rfh, $child_wfh) = (new IO::Handle, new IO::Handle);
      my($child_rfh, $parent_wfh) = (new IO::Handle, new IO::Handle);

      pipe ($parent_rfh, $child_wfh);
      pipe ($child_rfh, $parent_wfh);
# Does not work on WinNT
#      socketpair($child_fh, $parent_fh, AF_UNIX, SOCK_STREAM,
PF_UNSPEC)
#         or die "$0: socketpair failed: $!";
      $child_wfh->autoflush;
      $parent_wfh->autoflush;

      $Swap_fh{$child_rfh} = $child_wfh;
      $Swap_fh{$child_wfh} = $child_rfh;

      my $pid;
      if ($pid = fork) {
         # Parent code section
         close $parent_wfh; close $parent_rfh;
         $write_select->add ($child_wfh); # Start out writing to all
children
         print "forking child $child\n";
      }
      else {
         # Child starts here
         die "$0: cannot fork: $!" unless defined $pid;
         close $child_wfh; close $child_rfh;
         close STDIN; close STDOUT;
#         $SIG{'ALRM'} = sub { die 'alarmed' };
         my $ip;
         # Child just loops here accepting IP address to proccess
         while (defined($ip = <$parent_rfh>)) {
            # Get IP to resolve
            chomp ($ip);
            my $host = undef;
            eval {
               # Try to resolve, but give up after $TIMEOUT seconds
 #              alarm ($TIMEOUT);
               my $ip_struct = inet_aton $ip;
               $host = gethostbyaddr $ip_struct, AF_INET;
 #              alarm(0);
            };
            $host ||= $ip;
            # Print/write the ip to hostname back to parent.
            print $parent_wfh "$ip $host\n";
         }
         exit 0;
      }
   }
}






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

Date: Mon, 26 Feb 2001 19:11:54 GMT
From: David Bakhash <cadet@alum.mit.edu>
Subject: Re: Problem wit ActiveState on NT IPC(pipes) and fork
Message-Id: <m3g0h1ramh.fsf@alum.mit.edu>

I apologize for replying with this, but after much pain trying to do
stuff just like this no NT, I just finally gave up.  Signals, IPC, and 
multitasking is not worth the pain on NT.

The exact problems I got were hangs, and those are the worst.
Considering that your code is more complex than mine, I certainly can
see why you're having problems.

Isn't there some kind of Cygwin fork() for NT?  If there is (and I
think I've heard something like that), then maybe it's possible to go
back to using fork() in Perl.  That would also make code more portable 
between NT and Unix systems.

dave


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

Date: Mon, 26 Feb 2001 12:01:43 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: question about 'for' loop functionality
Message-Id: <3c2l9t03fqjoa2j67toq5l34kprg3n78oe@news.supernews.net>

David <NOSPAM4MEdrh@engineer.com> wrote:

} But what if I want to cycle through all elements of @array as well as
} initialize $count then auto increment it:
} 
} for ($count=1 ; @array ; $count++){
} 	#some code...
} }
} 
} This doesn't work. ...

Indeed it doesn't...:o)  But this is about as close as you can get to
duplicating the 'combined semantics' of the two ways of iterating over an
array:

   for ($count = 1; $count <= @array; $count += 1)
   {   local *_ = \$array[$count-1] ; 
      [use $count or $_ as you wish]
   }

  /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Mon, 26 Feb 2001 21:00:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: question about 'for' loop functionality
Message-Id: <hngl9t4i07qjke1k8llj02osngplg3jfbd@4ax.com>

David wrote:

>I have a question about 'for' loop functionality.
>
>I understand the following:
>
>for ($count=1 ; $count<10 ; $count++){
>	#some code...
>}  # no problem here
>
>And
>
>for (@array){
>	#some code with $_
>}   # now problem here either
>
>
>But what if I want to cycle through all elements of @array as well as
>initialize $count then auto increment it:
>
>for ($count=1 ; @array ; $count++){
>	#some code...
>}
>
>This doesn't work.

No it doesn't. You have been fooled by the fact that both control
structures use the same keyword; but they are in fact not related. So
you can't make a blend of them. People have complained about the lack of
control counter before, so maybe, some day, this might happen. In the
meantime, do one of these two things:

A)
	for my $i (0 .. $#array) {
	    my $item = $array[$i];
	    ... 
	    # now $i is the counter (first index always 0)
	    # and $item is a COPY of the current array item
	}

B)
	my $count = 1;
	for (@array) {
	    # $_ is an ALIAS for the current array item
	    # $count is a running counter, which can start anywhere
	    ...
	} continue {
	    $count++;
	}

-- 
	Bart.


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

Date: 26 Feb 2001 22:29:03 GMT
From: abigail@foad.org (Abigail)
Subject: Re: question on how to code a program
Message-Id: <slrn99lm5f.65u.abigail@tsathoggua.rlyeh.net>

Torque (gifg@netzero.netNOSPAM) wrote on MMDCCXXXIII September MCMXCIII
in <URL:news:3a96d6fc.15701003@nntp.ix.netcom.com>:
;; I'm trying to code a cgi program with perl to count the number of
;; years, months, days, hours, minutes, and seconds since a given date.

There are a bunch of modules on CPAN that will help you do this.

;; I thought I could use Matt's Script archive's countdown.pl as an
;; example and try to get it to work backwards, but it just isn't working
;; out.  I've decided to scrap that and start over.

The best way to deal with Matt's programs is to invent a time machine,
go back into history and kill Matts parents before he was conceived.
That would solve the Perl community from a big problem, in both the
past, present and future.

;; I think the best way to go about doing this is to take the date in
;; question and compare it to the current date... and find out how many
;; days difference there are between the two, then go ahead and figure
;; out how many months and years from there.


Go to CPAN. Look foor Date:: and Time:: modules.



Abigail
-- 
$;                                   # A lone dollar?
=$";                                 # Pod?
$;                                   # The return of the lone dollar?
{Just=>another=>Perl=>Hacker=>}      # Bare block?
=$/;                                 # More pod?
print%;                              # No right operand for %?


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

Date: Mon, 26 Feb 2001 21:27:38 -0000
From: "Chile" <abcd@ntlworld.com>
Subject: Re: Re: cgi-bin not excuting perl scripts. what have i done?
Message-Id: <hFzm6.29430$MN.773162@news2-win.server.ntlworld.com>

thanks for replying.

I got it working by cheating :)

I just reinstalled apache. Over kill maybe but it got it working alot
quicker than it would have taken me to figure it out.

Thanks again,
Scot

"Tim Hammerquist" <tim@vegeta.ath.cx> wrote in message
news:slrn99lgd0.5u9.tim@vegeta.ath.cx...
> Chile <abcd@ntlworld.com> wrote:
> > for some reason when i just type in the url like below
> >
> > http://192.168.1.101/cgi-bin/
> >
> > i normally get a IE permission denied error but instead now i get file
not
> > found?
>
> It sounds like you should get more familiar with Apache configurations
> (which fails to come under a Perl newsgroup's domain, but I'll see what
> I can do...)  =)
>
> Is your DocumentRoot still set to httpd/ ?  If so, Apache may be
> confused as to what you're trying to do.  A cgi-bin/ directory,
> correctly configured, will probably not display the content of the
> script, whereas normal html directories do.  Since your cgi-bin
> directory is a subdirectory of your DocumentRoot, it inherits
> DocumentRoot's permissions and will display the file.
>
> > "Chile" <abcd@ntlworld.com> wrote in message
> > news:PC6m6.24588$5n4.493852@news6-win.server.ntlworld.com...
> > > Hi,
> > >
> > > i have a linux box with apache on it and it was working fine last
night,
> > > running perl scripts from the cgi-bin no prob's but now when i try and
> > > access a scipt i get
> > >
> > > Not Found
> > > The requested URL /cgi-bin/counter.pl was not found on this server.
> > >
> > >
> > > i know the file is there as i can see it in the cgi-bin and can run it
> > perl
> > > counter.pl, witout problems.
> > >
> > > whats interesting is if i misspell counter.pl and try and run it i get
the
> > > IE file not found page so i don't know what this page error is coming
from
> > > or why.
>
> If you get the IE error page, then Apache simple returned an HTTP error
> code and IE returns its own explanation for why.  If you get any other
> page, in your case it's probably from Apache, telling you that something
> isn't set up correctly.
>
> > > Just to check, i went into the apache settings and changed the default
> > page
> > > from httpd/html to just httpd then i browsed to the cgi-bin and
clicked on
> > > the counter.pl but instead of executing it it just printed the file on
the
> > > screen like a txt file??
> > >
> > > i have changed it back now though.
>
> Oh, you have changed it back, eh?  Well, posting relevant sections of
> your conf file (such as DocumentRoot, ScriptAlias, Alias, Addhandler,
> Location, or Directory sections) and possibly some basic picture of
> your entire directory structure would help me get a much better idea of
> what's going on.  Or you might even just see what you can learn about
> your server itself.
>
> This is very off-topic, and shouldn't continue on clpm, but you may
> email me directly if you like.
>
> HTH
> --
> -Tim Hammerquist <timmy@cpan.org>
> Nearly all men can stand adversity, but if you
> want to test a man's character, give him power.
> -- Abraham Lincoln




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

Date: Mon, 26 Feb 2001 16:42:54 GMT
From: Alexandra <lanaS55nospam@hotmail.com>
Subject: receiving piped input???
Message-Id: <3A9A250D.28A7C78A@hotmail.com>

Consider this simple shell script:

#!/bin/sh
myprogram |  perl myperlscript

How do I read the output from myprogram inside of myperlscript???

Thanks,
Scott






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

Date: 26 Feb 2001 16:46:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: receiving piped input???
Message-Id: <97e18g$ddi$2@mamenchi.zrz.TU-Berlin.DE>

According to Alexandra  <lanaS55nospam@hotmail.com>:
> Consider this simple shell script:
> 
> #!/bin/sh
> myprogram |  perl myperlscript
> 
> How do I read the output from myprogram inside of myperlscript???

From STDIN.

Anno


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

Date: Mon, 26 Feb 2001 10:36:50 -0800
From: "Mahesh A" <maheshasolkar@yahoo.com>
Subject: Re: receiving piped input???
Message-Id: <t9l8i33rameide@corp.supernews.com>

> #!/bin/sh
> myprogram |  perl myperlscript
>
> How do I read the output from myprogram inside of myperlscript???

open (CMD, "ls -al |"); # Pipe at the end of the command means that I am
                        # reading from the command. If it were at the
beginning,
                        # - "| ls -al" - I could write in to the command (of
course
                        # not 'ls -al')
my @lsData = <CMD>;
close (CMD);

hth,
M.





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

Date: Mon, 26 Feb 2001 20:51:43 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: receiving piped input???
Message-Id: <slrn99lgss.5u9.tim@vegeta.ath.cx>

Alexandra <lanaS55nospam@hotmail.com> wrote:
> Consider this simple shell script:
> 
> #!/bin/sh
> myprogram |  perl myperlscript
> 
> How do I read the output from myprogram inside of myperlscript???

: #!/usr/bin/perl
: # myperscript - reads piped input
: 
: while( <> ) {
: 	# do stuff with lines input
: }

See documentation re. the 'diamond' operator for simple filter creation.

Can't search perldoc for you right now, but you have it right?  ;)

-- 
-Tim Hammerquist <timmy@cpan.org>
Never put off until tomorrow that
which can be done the day after tomorrow.
	-- Mark Twain


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

Date: 26 Feb 2001 22:33:40 GMT
From: abigail@foad.org (Abigail)
Subject: Re: RFD - comp.lang.perl.db, comp.lang.perl.network, comp.lang.perl.regex
Message-Id: <slrn99lme4.65u.abigail@tsathoggua.rlyeh.net>

Jon Ericson (Jonathan.L.Ericson@jpl.nasa.gov) wrote on MMDCCXXXIII
September MCMXCIII in <URL:news:86itm1x917.fsf@jon_ericson.jpl.nasa.gov>:
'' 
'' I don't think you gain much by creating this group.  Most database
'' related traffic is of the form:
'' 
'' Q: How do I use perl to interface with database X?
'' A: Use DBI.


You forget the 60% of the questions that have nothing to do with Perl,
but are either SQL questions, or database specific questions.


Abigail
-- 
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;        
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";


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

Date: Mon, 26 Feb 2001 14:28:38 -0800
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: shell script to perl (NEWBIE)
Message-Id: <97elap$p1p@news.or.intel.com>

Hi

I was trying to convert a shell script *.sh to perl script.
In the shell script the statement
setenv THENAME  /dir1/file1
in perl i used system("setenv THENAME  /dir1/file1);
It says can't execute setenv..no such file or directory
Please help

Thanks in advance




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

Date: Mon, 26 Feb 2001 18:56:36 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Simple question about change of base
Message-Id: <EFxm6.19198$Sl.841446@iad-read.news.verio.net>

Hello,

	Here's a simple question. I would like to convert a base 10 number
into a base 32 number, i.e. [0-31] -> [0-9a-z] (lower case letters are
preferable). Is there a simple way to do this in Perl? 


-- 
World's Greatest Living Poster


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

Date: Mon, 26 Feb 2001 19:35:28 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Re: Simple question about change of base
Message-Id: <4eym6.19206$Sl.841578@iad-read.news.verio.net>

In article <EFxm6.19198$Sl.841446@iad-read.news.verio.net>,
James Weisberg <chadbour@wwa.com> wrote:
>Hello,
>	Here's a simple question. I would like to convert a base 10 number
>into a base 32 number, i.e. [0-31] -> [0-9a-z] (lower case letters are
>preferable). Is there a simple way to do this in Perl? 

	Doop! I mean a base 36 number! [0-35] -> [0-9a-z]. 

	Sorry about that...

-- 
World's Greatest Living Poster


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

Date: Mon, 26 Feb 2001 11:55:46 -0800
From: "Mahesh A" <maheshasolkar@yahoo.com>
Subject: Re: Simple question about change of base
Message-Id: <t9ld634dbfte3b@corp.supernews.com>

"James Weisberg" <chadbour@wwa.com> wrote in message
news:EFxm6.19198$Sl.841446@iad-read.news.verio.net...
> Here's a simple question. I would like to convert a base 10 number
> into a base 32 number, i.e. [0-31] -> [0-9a-z] (lower case letters are
> preferable). Is there a simple way to do this in Perl?

If you want to convert a base 10 (integer) into a base32 number, here's a
subroutine...

sub getBase32 () {
    my $num = $_[0];
    my $num32 = "";
    my @Digits = (('a'..'z'),(2..7));

    do {
        $num32 = $Digits[(($num)%32)].$num32;
    } while (($num /= 32) >= 1);

    return $num32;
}

It uses this table for conversion

                    Table 1: Base32 conversion
             bits   char  hex         bits   char  hex
             00000   a    0x61        10000   q    0x71
             00001   b    0x62        10001   r    0x72
             00010   c    0x63        10010   s    0x73
             00011   d    0x64        10011   t    0x74
             00100   e    0x65        10100   u    0x75
             00101   f    0x66        10101   v    0x76
             00110   g    0x67        10110   w    0x77
             00111   h    0x68        10111   x    0x78
             01000   i    0x69        11000   y    0x79
             01001   j    0x6a        11001   z    0x7a
             01010   k    0x6b        11010   2    0x32
             01011   l    0x6c        11011   3    0x33
             01100   m    0x6d        11100   4    0x34
             01101   n    0x6e        11101   5    0x35
             01110   o    0x6f        11110   6    0x36
             01111   p    0x70        11111   7    0x37

But I am not sure f you want to do exactly this. Have a look at ...

http://search.cpan.org/doc/MIYAGAWA/Convert-RACE-0.01/lib/Convert/Base32.pm

http://www.ietf.org/internet-drafts/draft-ietf-idn-race-03.txt

hth,
M.




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

Date: Mon, 26 Feb 2001 11:59:33 -0800
From: "Mahesh A" <maheshasolkar@yahoo.com>
Subject: Re: Simple question about change of base
Message-Id: <t9ldd8gkfnifd6@corp.supernews.com>

>
> Doop! I mean a base 36 number! [0-35] -> [0-9a-z].
Well, then its ..

sub getBase36 () {
    my $num = $_[0];
    my $num36 = "";
    my @Digits = ((0..9), ('a'..'z'));

    do {
        $num36 = $Digits[(($num)%36)].$num36;
    } while (($num /= 36) >= 1);

    return $num36;
}





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

Date: 26 Feb 2001 20:15:59 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Simple question about change of base
Message-Id: <983217722.28149@itz.pp.sci.fi>

In article <EFxm6.19198$Sl.841446@iad-read.news.verio.net>, James Weisberg wrote:
>
>	Here's a simple question. I would like to convert a base 10 number
>into a base 32 number, i.e. [0-31] -> [0-9a-z] (lower case letters are
>preferable). Is there a simple way to do this in Perl? 

Hmm.. there are 26 letters in the alphabet, not 22.  Anyway, here's a
generic method:

  my @sym = (0..9, 'a'..'v');  # 32 elements
  my $text = '';
  do { $text = $sym[$num % @sym] . $text } while $num = int($num / @sym);

For a power of 2 like 32, you could maybe also use pack/unpack, but I
rather doubt that would be any more efficient.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"So I put in a order for 100 floppies, and they send me 100 boxes (10000
 floppies). This supply will last me till 3.5" Floppy Disks or me are
 something of the past."                  -- Rob Hagman in the monastery

Please ignore Godzilla and its pseudonyms - do not feed the troll.


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

Date: Mon, 26 Feb 2001 21:32:14 GMT
From: trammell@bayazid.hypersloth.net (John Joseph Trammell)
Subject: Re: Simple question about change of base
Message-Id: <slrn99lgl5.ra9.trammell@bayazid.hypersloth.net>

On Mon, 26 Feb 2001 18:56:36 GMT, James Weisberg <chadbour@wwa.com> wrote:
> Hello,
> 
> 	Here's a simple question. I would like to convert a base 10 number
> into a base 32 number, i.e. [0-31] -> [0-9a-z] (lower case letters are
> preferable). Is there a simple way to do this in Perl? 

[0-9a-z] is 36 characters.  How about [0-9a-v]?

use integer;

sub base32
{
    my $dec = shift;
    my @dig;
    while ($dec) { push @dig, $dec % 32; $dec /= 32; }
    return join "", reverse map { ($_ < 10) ? $_ : chr($_+87) } @dig;
}



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

Date: Mon, 26 Feb 2001 21:52:17 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Simple question about change of base
Message-Id: <t9lk0ho6ver404@corp.supernews.com>

James Weisberg (chadbour@wwa.com) wrote:
: >	Here's a simple question. I would like to convert a base 10 number
: >into a base 32 number, i.e. [0-31] -> [0-9a-z] (lower case letters are
: >preferable). Is there a simple way to do this in Perl? 
: 	Doop! I mean a base 36 number! [0-35] -> [0-9a-z]. 


#!/usr/bin/perl -w
# base36 - function (and test harness) to convert base-10 input numbers
#  into base 36 (0-9,a..z) numbers.
# Craig Berry (20010226)

use strict;

sub base36($) {
  my $b10 = shift;
  my $b36 = '';
  my @digits = ( 0..9, 'a'..'z' );

  while ($b10) {
    $b36 .= $digits[$b10 % 36];
    $b10  = int($b10 / 36);
  }

  return (scalar reverse $b36) || '0';
}

while (<>) {
  print base36($_), "\n";
}


-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Mon, 26 Feb 2001 19:03:51 GMT
From: David Bakhash <cadet@alum.mit.edu>
Subject: Re: simple question on array splice hack
Message-Id: <m3k86drazv.fsf@alum.mit.edu>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

> One-liner?  Well...
> 
> unshift @a, splice @a, (grep defined $a[ $_]->{ $swap_this}, 0 .. $#a)[0], 1;
>
> [...preserving order]
>
> unshift @a, splice @a, $i, 1; # this rotates the first $i+1 elements

thanks!  that's exactly what I was looking for.

dave


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

Date: Mon, 26 Feb 2001 18:06:04 GMT
From: Bruno De Wolf <bruno.dewolf@eozen.com>
Subject: SSL tunneling
Message-Id: <3A9A9A9D.6FEB5F04@eozen.com>

There seem to be other people with the same problem. Some succeed in
using LWP to send https request through a proxy, I'am in the set of
unlucky ones... I just can't get it to work.

Here's my config:
Activeperl 5.6 (build 613) running on win NT 4.0 SPP6
libwww 5.48 with Chris Hiner's patch applied (
http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/2000h2/0209.html)

crypt-ssleay 0.17.1

Here's the script:
use LWP::UserAgent;
use LWP::Debug qw(+);

  $tgurl = 'https://silopolis.com/';

# Send the message
    my $ua = LWP::UserAgent->new;
    $ua->proxy(http   => 'http://127.0.0.1:80');
    $ua->proxy(https  => 'https://127.0.0.1:80/');
    my $req = HTTP::Request->new(GET =>'https://silopolis.com/');
    my $res = $ua->request($req);
    if ($res->is_success)
    {
      print $res->as_string;
    }
    else
    {
      print "Failed: ", $res->status_line, "\n";
      print $res->as_string;
    }

--> The proxy connect seems to work OK, but the actual request results
in an 'ssl negotiation failure'. Note that the same code without a proxy

works fine.

Any help on this subject is greatly appreciated.

Bruno De Wolf




--
!!
!!  New e-mail address:
!!
!!  Please note my change of e-mail address.
!!  As of January 15, 2000 you can mail me at: bruno.dewolf@eozen.com
!!  Sorry for any inconvenience
!!
!!  Bruno De Wolf




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

Date: Mon, 26 Feb 2001 21:41:43 -0000
From: "Chile" <abcd@ntlworld.com>
Subject: Would the Net::FTP and LWP modules cope in an industrial strength enviroment??
Message-Id: <yQzm6.29474$MN.779475@news2-win.server.ntlworld.com>

Hi,

I have got experience with many NT components such as httget and upload
components that work quite well under heavy load.

I was just wondering if this is true with the Net::FTP and LWP modules? I.e.
would these things cope in an industrial strength enviroment.

Ie i am planning to create a qeue where files are off loaded onto one script
which will connect and then upload files to varuious servers. these will be
pretty much non stop and i am just trying to find out of either of these
modules are likely to be criples by heavy work loads??

If anyone has any opinions as to other ways of doing this i would like to
here it...

Thanks,
Scott






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

Date: 26 Feb 2001 22:16:26 GMT
From: blah@blah.blah.invalid
Subject: Re: Would the Net::FTP and LWP modules cope in an industrial strength enviroment??
Message-Id: <97ekjq$25b8$1@newssvr05-en0.news.prodigy.com>

Chile <abcd@ntlworld.com> wrote:
> I was just wondering if this is true with the Net::FTP and LWP modules? I.e.
> would these things cope in an industrial strength enviroment.
> 
> Ie i am planning to create a qeue where files are off loaded onto one script
> which will connect and then upload files to varuious servers. these will be
> pretty much non stop and i am just trying to find out of either of these
> modules are likely to be criples by heavy work loads??

Net::FTP and LWP will do just fine.  Depending on exactly what
you're trying to do, you might also look at a utility like rsync
(http://rsynch.samba.org).

Eric


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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