[19188] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1383 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 26 09:05:44 2001

Date: Thu, 26 Jul 2001 06:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <996152710-v10-i1383@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 26 Jul 2001     Volume: 10 Number: 1383

Today's topics:
    Re: errata for book "PERL DEBUGGED"?  (no url in book!) <krahnj@acm.org>
        Error handling <> <somsom@freemail.c3.hu>
    Re: Error handling <> <krahnj@acm.org>
    Re: Error handling <> <somsom@freemail.c3.hu>
    Re: Error handling <> <paul.johnston@dsvr.co.uk>
    Re: Error handling <> nobull@mail.com
        Extract the relative sorting of items from multiple lis <bart.lateur@skynet.be>
        FAQ: How do I validate input? <faq@denver.pm.org>
    Re: Fork(): How to find out? ... (Anno Siegel)
    Re: how to clean a text file (need to cut some spaces)  (George)
    Re: How to convert Pc/Unix characterset (ISO-lat1) to t <gnarinn@hotmail.com>
        Informix IDS2000 and Zope/Python/Perl/PHP on Linux <worm@gdp-group.com>
        Linux Web Administration Interface (Hannes Schulz)
    Re: MSI Perl package installation from ActivePerl for w (Helgi Briem)
        Newbie Question: Memory Problem (Johannes Ludsteck)
    Re: Newbie Question: Memory Problem <ilya@martynov.org>
    Re: Newbie Question: Memory Problem <krahnj@acm.org>
    Re: newbie: storing multiple objects in a hash (rolf deenen)
    Re: Object Reuse with Net::FTP <Thomas@Baetzler.de>
    Re: probs. passing filehandels and scope issues (Anno Siegel)
    Re: regex question - sort of - how to count if the stri (Anno Siegel)
        Regexp help - ??? (Tracy Gentry)
    Re: scroll text on text-modal console? <Thomas@Baetzler.de>
    Re: Single char formats => core dump?!? <Thomas@Baetzler.de>
        viewing input from a form (rolf deenen)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 26 Jul 2001 11:24:57 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: errata for book "PERL DEBUGGED"?  (no url in book!)
Message-Id: <3B5FFDEF.7CD4760@acm.org>

David Combs wrote:
> 
> I bought a copy of this new book, "Perl Debugged", and
> have found what I (mistakenly?) think are errors in
> his example programs.
> 
> But unlike O'Reilly books, which have easy-to-find
> errata, and they tell you so in the intro, with
> this book (addison wesley), there is NO mention at
> all of any errata, or where to send any you might find,
> or where to get a copy of what's been turned in --
> OR even where to get already-typed-in code from the
> book.
> 
> Nothing!
> 
> ---
> 
> Did I look at addison wesley.  No way!  I tried that
> once before; just about *impossible* to find *anything*
> via their site.
> 
> (Does no higher management ever look at O'Reilly's site?
> What a bunch of idiots for not doing that!)
> 
> ----
> 
> Anyway, does anyone here know the url for the errata,
> etc?
> 
> It'd be real nice to have it...

Gee, and it only took me a few seconds to find it with Google.



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 26 Jul 2001 10:08:00 GMT
From: Som-Som <somsom@freemail.c3.hu>
Subject: Error handling <>
Message-Id: <3B5FEBB0.6010001@freemail.c3.hu>

Hi,

I am writting my first Perl program. It is almost ready, but I have a 
problem. I don't know how to handle errors when I read STDIN/files the 
following way:

#!/bin/perl
while(<>) {
     print; #do something very important
}

I want my own custom error message to be displayed.

Som-Som



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

Date: Thu, 26 Jul 2001 11:33:51 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Error handling <>
Message-Id: <3B600056.20FDE9FC@acm.org>

Som-Som wrote:
> 
> Hi,
> 
> I am writting my first Perl program. It is almost ready, but I have a
> problem. I don't know how to handle errors when I read STDIN/files the
> following way:
> 
> #!/bin/perl
> while(<>) {
>      print; #do something very important
> }
> 
> I want my own custom error message to be displayed.

The usual way to display error messages is to send them to STDERR the
standard error file handle.

print STDERR "Your error message\n";



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 26 Jul 2001 12:03:07 GMT
From: Som-Som <somsom@freemail.c3.hu>
Subject: Re: Error handling <>
Message-Id: <3B6006AC.5090807@freemail.c3.hu>

>>#!/bin/perl
>>while(<>) {
>>     print; #do something very important
>>}

 >

> The usual way to display error messages is to send them to STDERR the
> standard error file handle.
> 
> print STDERR "Your error message\n";


Let's name the program above "proggy.pl". Now enter the following 
command where file named "nofile" does not exist:
proggy.pl nofile

You will get an error message like:
Can't open nofile: No such file or directory at ./proggy.pl line 2.

I want to avoid error message generated by perl showing up (and show my 
own by print STDERR "No such file...";).



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

Date: Thu, 26 Jul 2001 13:08:15 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: Error handling <>
Message-Id: <3B60082F.71D6B85F@dsvr.co.uk>

Hi,

> You will get an error message like:
> Can't open nofile: No such file or directory at ./proggy.pl line 2.
> I want to avoid error message generated by perl showing up (and show my
> own by print STDERR "No such file...";).

You need to open the files up yourself then:

for $file (@ARGV)
{
  open(FILE, $file) or die "Can't open '$file': $!";
  while(<FILE>)
  {
    # stuff
  }
  close(FILE);
}


Paul


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

Date: 26 Jul 2001 13:07:00 +0100
From: nobull@mail.com
Subject: Re: Error handling <>
Message-Id: <u91yn351y3.fsf@wcl-l.bham.ac.uk>

Som-Som <somsom@freemail.c3.hu> writes:

> >>#!/bin/perl
> >>while(<>) {
> >>     print; #do something very important
> >>}
> 
> Let's name the program above "proggy.pl". Now enter the following 
> command where file named "nofile" does not exist:
> proggy.pl nofile
> 
> You will get an error message like:
> Can't open nofile: No such file or directory at ./proggy.pl line 2.
> 
> I want to avoid error message generated by perl showing up (and show my 
> own by print STDERR "No such file...";).

In general you can trap errors by wrapping code in eval{} and then
examining the value of $@.

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


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

Date: Thu, 26 Jul 2001 12:27:13 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Extract the relative sorting of items from multiple lists
Message-Id: <7720mtckves61t97df20afpok8grrejjn5@4ax.com>

I've got a cute little problem here. It's actually more of a question
for a proper algorithm, than a specific perl problem.

I have to extract the ordering of each item in some arrays, and not
every item is present in every array. For example:

	@list = ([qw(A C F)], [qw(A B C)], [qw(A C D E)], [qw(E F)]);

From this, I'd need to deduce that 'B' comes before 'C' and after 'A',
and so on, so I'd eventually have to come up with the list qw(A B C D E
F). How would you do that?

If there's more than one solution, any solution will do, and if there's
a conflict, e.g. between orderings qw(A B C) and qw(C A), I'd like to be
warned about it.

As a thought for a starting point: for qw(A C F), I'd assign a number to
each entry, for example (A => 1, C => 2, F => 3), and try to assign
intermediate values for values that have to come in between existing
items. The big question is how to mark unresolved relative orderings,
for example before examining the last entry in the above example list,
you know that 'D' comes after 'C'; and that 'F' comes after 'C'. So
where does 'F' stand relative to 'D'? Unresolved. And what about 'E'? It
comes after 'D', true... but in relation to 'F'?

-- 
	Bart.


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

Date: Thu, 26 Jul 2001 12:17:14 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I validate input?
Message-Id: <eTT77.73$os9.212264960@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How do I validate input?

    The answer to this question is usually a regular expression, perhaps
    with auxiliary logic. See the more specific questions (numbers, mail
    addresses, etc.) for details.

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.17
-- 
    This space intentionally left blank


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

Date: 26 Jul 2001 11:36:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Fork(): How to find out? ...
Message-Id: <9jovbf$kcn$1@mamenchi.zrz.TU-Berlin.DE>

According to Vit Hotarek  <xhotarek@fi.muni.cz>:
> 
> Hello,
> 
>    Is there any way how to find out,
>    how many forked children are actually
>    running?
> 
>    When I run the program below, everything
>    works OK, but when it gets to (*), I have
>    wrong number of entries in the @children array.
>    E.g., I am seeing (ps command) 3 running processess,
>    but scalar @children yields zero or any other
>    wrong value.
> 
>    Could you please help with solving this problem?
> 
> 
>    Many thanks.
> 		Vit Hotarek
>    
>       
>   
>      .....
> 
>      $SIG{CHLD} = \&wait_for_child;
>      $| = 1;
> 
> 
>      $i = 1;
>      @children = ();
> 
>      while ($i < 6)       # to do 5 children
>      {
>        $pid = fork();
> 
>           if ($pid == 0)  # I am a child 
>           {
>              do_something();
>              exit(0);
>           }
>           elsif ($pid > 0) # I am a parent
>           {
>              push(@children, $pid); # Push $pid into @children
>              # scalar @children = nr. of running children
>           }
>           ...
> 
>        $i++;
>      }#end while
> 
>      (*)
>      while (scalar(@children) > 0)  # Empty @children = no running children
>      {
>        sleep(1);
>      }
>      # It should loop until all children are finished
> 
>      .......
>      exit(0);
> 
> 
>      
>      sub wait_for_child            #REAPER
>      {
>         my ($child, $x);
>  
>         $child = wait;
>         $x = shift(@children); # scalar @children -= 1;
>         # Pop an entry from @children.
>         # = decrease nr. of running children
>         
> 
>         $SIG{CHLD} = \&wait_for_child;
>      }

Do you realize that the PIDs in @children have no relation to
the PIDs of outstanding child processes?  You are deleting the
PIDs in the sequence you started them, which is usually not
the same as the sequence they're dying.  A simple counter
(as your $i) would serve the same purpose with less potential
for misinterpretation.

Your wait_for_child() doesn't catch all children because it isn't
called again when a SIGCHLD arrives while it is still processing
another.  You must call wait() in a loop to take care of those.

Change it like this:

     sub wait_for_child            #REAPER
     {
        my ($child);
        while ( ($child = wait) != -1 ) {
            @children = grep $_ != $child, @children;
        }
        $SIG{CHLD} = \&wait_for_child;
     }

Anno


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

Date: 26 Jul 2001 04:40:26 -0700
From: argeo@4u.net (George)
Subject: Re: how to clean a text file (need to cut some spaces) [quite newbie ;]
Message-Id: <a42827b0.0107260340.77382eb7@posting.google.com>

Yes, this works perfectly.
Thanks you all for your input !

George


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

Date: Thu, 26 Jul 2001 10:18:36 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: How to convert Pc/Unix characterset (ISO-lat1) to the Mac character set
Message-Id: <996142716.383874631021172.gnarinn@hotmail.com>

In article <9jjo3c$9q8$1@news1.xs4all.nl>,
Louis Banens <louis.banens@xs4all.nl> wrote:
>
>Can anybody tell me how to convert Pc/Unix characterset (ISO-lat1) to the
>Mac character set. We have problems with extende characters uploaded from a
>Mac to a PC/Unix system. Are there any perl routines available for this.
>
look at Convert::* on CPAN
Convert::Translit and Convert::Recode look promising
Text::ConvertPlatform also sounds relevant

(note: I am just going by the module names and descriptions as shown
on search.cpan.org after a quick search for 'convert'. there might other
modules there that suit you better)

gnari


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

Date: Thu, 26 Jul 2001 14:38:31 +0200
From: Thomas Volkmar Worm <worm@gdp-group.com>
Subject: Informix IDS2000 and Zope/Python/Perl/PHP on Linux
Message-Id: <3B600F47.2F59C1FC@gdp-group.com>

Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------9F53CD9DBC433760339201AB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi all!

I am consindering to use Informix Dynamic Server (Informix Internet
Foundation 2000/Linux) together with Zope and the other 3 P's.

I wonder, whether somebody has any experience with Linux and

- IDS 2000 and Perl
or
- IDS 2000 and PHP
or
-  IDS 2000 and Python
or
- IDS 2000 and Zope

and can tell me about the experience he made with one or more of these
combinations. I am interested to hear about

- availibility of the needed drivers
- their (practical) compatibility to (eg. perl DBI, python DB-API 2.0,
etc.)
- stability
- and what else someone has experienced

I already was an php.net, python.org, perl.org, zope.org - I guess I
know whats available. It looks to me as if the support for IDS is not so
strong, so I am really interested in real experience somebody had rather
that what you can read in the READMEs. If you stopped using IDS together
with P..., please tell me why and what db (other than mySQL, thats
allready running here) are you using instead.

If some Informix/IBM people are around: Are there any contributions
planned or in progress for the 3 P's by Informix/IBM? Where can I find
online information about it?

If you respond to this posting, please send a CC to my email-address
too.

Thanks for your efforts in advance

Regards
Thomas Volkmar Worm


--------------9F53CD9DBC433760339201AB
Content-Type: text/x-vcard; charset=us-ascii;
 name="worm.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Visitenkarte für Thomas Volkmar Worm
Content-Disposition: attachment;
 filename="worm.vcf"

begin:vcard 
n:Thomas Volkmar;Worm
tel;fax:+49 (0)40 / 29 8 76-127
tel;work:+49 (0)40 / 29 8 76-0
x-mozilla-html:FALSE
url:www.gdp-group.com
org:gdp Markt- und Meinungsumfragen GmbH 
adr:;;Richardstrasse 18;Hamburg;Hamburg;22081;D
version:2.1
email;internet:worm@gdp-group.com
title:IT Consultant
x-mozilla-cpt:;15152
fn:Worm, Thomas Volkmar
end:vcard

--------------9F53CD9DBC433760339201AB--



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

Date: 26 Jul 2001 03:19:09 -0700
From: h_schulz@gmx.de (Hannes Schulz)
Subject: Linux Web Administration Interface
Message-Id: <9130a43b.0107260219.5966bfd2@posting.google.com>

Hi comp.lang.perl.misc,

I'm planning to write a Linux administration interface controlled by
perl CGI scripts on a http server in my local net. I know that sounds
like Webmin, but I want to restrict certain actions to special users,
and create my own more userfriendly design (not speaking of wanting to
learn more about perl).

Now the scripts run by the webserver can not execute or modify any
system stuff. I considered writing everything into a file and letting
a cronjob check that file, but since I need the changes fast, this is
not the best Idea, or is it? A deamon process controlled by signals?
Or one that waits for socket connections from localhost? I could not
figure out what Webmins foreign_call() procedure does, but I guess
that is what I need. And, after all that, what would be most secure?

I thank you in advance for your response!
  Hannes Schulz


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

Date: Thu, 26 Jul 2001 12:24:37 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: MSI Perl package installation from ActivePerl for win98
Message-Id: <3b600a80.272831841@news.isholf.is>

On 25 Jul 2001 15:28:24 -0700, razvan.mihailescu@gartner.com
(Razvan Mihailescu) wrote:

>Hello,
>
>1. I got MSI for win98 from this link to install Perl on my machine:
>http://aspn.activestate.com/ASPN/Downloads/ActivePerl/

Good.

>2. I ran the .msi file I got from ActivePerl

Good

>3. I typed "perl -v" to test, and it told me I didn't have
>"win32gnu.dll"

That's very strange.  I've been running perl on win32
for years and I've never heard of or seen that file.

>4. I searched for "win32gnu.dll" on the web, found it, and copied it
>on my
>c:\windows\system and c:\windows\system32

Dangerous and perhaps premature.

>5. I then went to the DOS prompt again, typed "perl -v" to see if it
>would work, and I got this:
>	
>	this is perl version 4.0
>	perl for NT $$Revision 4.0.1.8
>	patch level: 36

Now that's strange.  Really strange. I get:
This is perl, v5.6.0 built for MSWin32-x86-multi-thread

>Is this good or bad? It says "perl for NT" not perl for win98

That´s OK in itself.  Perl is exactly the same for both.
But perl version 4.0.  How the hell did that get in there?

>6. I then typed perl -MCGI -e "print $CGI::VERSION" and I got this:
>
>	unrecognized switch: -MCGI

I get 2.74.

>What does this tell you? I'm lost.

I think you have previously installed an older version of
perl, possibly with a web server or something and failed
to set your new perl as the default version.  Uninstall 
both and start over.

Regards,
Helgi Briem



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

Date: 26 Jul 2001 12:18:29 GMT
From: johannes_ludsteck@gmx.de (Johannes Ludsteck)
Subject: Newbie Question: Memory Problem
Message-Id: <9jp1ql$3pl$1@rrzd1.rz.uni-regensburg.de>

Dear Guru's,
I would like to process a _VERY_ hug ASCII File (about 300MB).
When I set up the procedure in perl:

open(outfile,">o.txt");
open(infile,"<in.txt");
foreach $line (<infile>) {
        <extract something from $line... and write it to o.txt>.
};
 ...

Then perl tries to load the whole file into memory and runs out of memory.
Is there no way to read the file line by line?


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

Date: 26 Jul 2001 16:46:51 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Newbie Question: Memory Problem
Message-Id: <87n15rj1s4.fsf@abra.ru>


JL> Dear Guru's,
JL> I would like to process a _VERY_ hug ASCII File (about 300MB).
JL> When I set up the procedure in perl:

JL> open(outfile,">o.txt");
JL> open(infile,"<in.txt");
JL> foreach $line (<infile>) {
JL>         <extract something from $line... and write it to o.txt>.
JL> };
JL> ...

JL> Then perl tries to load the whole file into memory and runs out of memory.
JL> Is there no way to read the file line by line?

Such cycle should read file line by line. Something else is leaking
memory but it is hard to say what without seeing what are you doing in
cycle body.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Thu, 26 Jul 2001 12:53:21 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Newbie Question: Memory Problem
Message-Id: <3B60134D.7A43100C@acm.org>

Johannes Ludsteck wrote:
> 
> Dear Guru's,
> I would like to process a _VERY_ hug[sic] ASCII File (about 300MB).
> When I set up the procedure in perl:
> 
> open(outfile,">o.txt");

You should _always_ check the return value from open.

open OUTFILE, '> o.txt' or die "Cannot open o.txt: $!";

> open(infile,"<in.txt");

open INFILE, '< in.txt' or die "Cannot open in.txt: $!";

> foreach $line (<infile>) {
>         <extract something from $line... and write it to o.txt>.
> };
> ...
> 
> Then perl tries to load the whole file into memory and runs out of memory.
> Is there no way to read the file line by line?

Yes, use while instead of foreach.

while ( <INFILE> ) {



John
-- 
use Perl;
program
fulfillment


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

Date: 26 Jul 2001 04:12:47 -0700
From: rdeenen@mollymail.com (rolf deenen)
Subject: Re: newbie: storing multiple objects in a hash
Message-Id: <5b51a4e6.0107260312.6ea873ae@posting.google.com>

Thanks for the reaction everyone. It's been really helpful...

Greet,

Rolf Deenen


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

Date: Thu, 26 Jul 2001 12:45:28 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Object Reuse with Net::FTP
Message-Id: <vusvltopp0q6g8973a2qal1shh5v0p5vd2@4ax.com>

On 25 Jul 2001,  jeffrey.hill1@tycoelectronics.com (Jeff Hill) wrote:
>I am writing a batch processing FTP program that needs to log into
>multiple servers.
[...]
>The first part of that works fabulously!  Unfortunately, when I log
>off the first server and go into the next server, I am unable to log
>into the next server.  I'm trying to use the same variable (I've set
>the '$ftp' variable as a global variable and used it in all the subs,
>I know it's a bad practice, but I'm still a little unsure about using
>objects in Perl).
[...]

This isn't particularly hard. Try the following code skeleton:

-8<--------( cut here )----------
#!/usr/bin/perl -w

use strict;
use Net::FTP;

sub ftp_login {
  my ( $host, $user, $pass ) = @_;

  my $ftp = Net::FTP->new( $host );

  if( $ftp ){

    if( $ftp->login( $user, $pass ) ){

      if( !$ftp->binary() ){
        warn "Setting binary transfer mode for '$host' failed: $@";
        $ftp->close();
        $ftp = undef;
      }

    } else {
      warn "FTP login to '$host' failed: $@";
      $ftp->close();
      $ftp = undef;
    }

  } else {
    warn "FTP connection to '$host' failed: $@";
  }

  return( $ftp );
}


sub ftp_logout {
  my $ftp = shift;

  if( defined($ftp) ){
    if( !$ftp->close() ){
      warn "FTP connection close reported an error!";
    }
  } else {
    warn "FTP connection was not defined!";
  }
}

my @hostdata = (
  { 'host' => 'i.dont.no', 'user' => 'foo', 'pass' => 'bar' },
  { 'host' => '127.0.0.1', 'user' => 'gaga', 'pass' => 'banane' }
);

foreach my $host (@hostdata){
  if( my $ftp = ftp_login( $host->{'host'},
                                  $host->{'user'},
                                  $host->{'pass'} ) ){
    print "connected to '$host->{'host'}'\n";
    
    # do something
    
    ftp_logout( $ftp );
  } else {
    print "FTP connect to '$host->{'host'}' failed!";
  }
}
-8<--------( cut here )----------

HTH,
-- 
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.


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

Date: 26 Jul 2001 10:42:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: probs. passing filehandels and scope issues
Message-Id: <9jos5t$i5k$1@mamenchi.zrz.TU-Berlin.DE>

According to Benjamin Goldberg  <goldbb2@earthlink.net>:
> Jason LaPenta wrote:

[...]
 
> > OUTPUT :
> > seek() on unopened file at ./process2.perl line 124.
> 
> You're not posting real code, since there is not "or die" after the
> seek, and thus nothing which would produce this error message.

No, "seek() on unopened..." is a warning.

Anno


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

Date: 26 Jul 2001 12:36:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regex question - sort of - how to count if the string has more than 25 words in it
Message-Id: <9jp2rl$n79$1@mamenchi.zrz.TU-Berlin.DE>

According to David Gurney <david_gurney@hotmail.com>:
> hi,
> 
> I'm trying to count the number of words in a string repeatedly. If the
> number is greater than 25 then the string is shortened and the entire
> string written to another file. The problem seems to be that the way
> I'm doing the count is very slow. can anyone show me a faster way than
> 
> 		$match = 0 ;
> 		while ($ttxts[$i]){
> 			if ($ttxts[$i] =~ /(\w+)/g){
> 				$match++ ;
> 				$tshrt .= "$1 ";
> 			}
> 		}
> 		if ($match <= 25){
> ##			do stuff
> 		}

Slow?  It's an infinite loop if $ttxts[ $i] contains anything
substantial, because that value is never changed.  Please post
code that you actually have run, not something vaguely similar.

If you want the number of words (as implicitly defined by your
regex), do this:

    my $match = () = $ttxts[$i] =~ /\w+/g;

The funny-looking assignment to () puts the pattern match in list
context.  Assigning the whole list assignment to a scalar gives the
number of elements that were assigned to (), as described in perlop
under "assignment".  So you get the number of matches.

To break the string into pieces of maximally 25 words, I'd go for a
combination of split with splice or slice.  It can be done in a
single regex, for instance

    my @parts = $ttxts[$i] =~ /((?:\b\w+\W*){1,25})/g;

but that's not very clear.

Anno


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

Date: 26 Jul 2001 05:48:35 -0700
From: tracy_gentry@yahoo.com (Tracy Gentry)
Subject: Regexp help - ???
Message-Id: <9d356f64.0107260448.52d34b66@posting.google.com>

I'm using the gnu.regex package in a Java environment. This may not be
the most appropriate newsgroup to post to, but after searching all day
for an answer this group seems to have the most discussion regarding
regular expressions.

I'm attempting to use reg expressions as masks to input fields. The
masks must match any subset of characters that are contained in a mask
(validation is done as the user types.) So a date mask, for example,
has to match on 2, 02, 2/, 2/21, 2/21/2, 2/21/2001, etc. Here's a
snippet of the expression I'm using for date validation:

 ...|"(0{0,1}2/29/20[02468][48]{0,1})|"|...

This line validates a subset of the valid leap years for this century.
As coded, 02/29/200 and 02/29/2004 will match, but 02/29/20 won't and
I want it to. Is there a way to denote a character as optional if no
other characters appear after it, but required if more characters
follow? Or maybe some sort of grouping?

Also, the web pages I've seen on regexp are kind of sparce. Does
anyone know of a good resource on the web?

Thanks,
Tracy Gentry


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

Date: Thu, 26 Jul 2001 13:02:26 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: scroll text on text-modal console?
Message-Id: <52uvlt85dh5if8p1m6hgearj6pfi2uqqo0@4ax.com>

On Thu, 26 Jul 200, MMX166+2.1G HD <no@mail.addr> wrote:
>just going to write a enhancing "more" tool that can scroll plain text
>forward and backward on the console (say dos command window), and.
>without TK module. what shall I do?

Install "less"? :-)

If you really want to do that, check out Curses.pm if you're on Unix
or Term::Cap if you have to make do with a Win32 platform.

HTH,
-- 
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.


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

Date: Thu, 26 Jul 2001 14:21:39 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Single char formats => core dump?!?
Message-Id: <ca10mtgh98sc7r946rvaoggfu8kubjq3j4@4ax.com>

Hi,

On Wed, 25 Jul 2001, Steve Roehling <steve@endrun.com> wrote:
>I'm doing some report formatting which needs to have single character 
>columns, with no spaces in between columns. I'm creating some formats on 
>the fly to do this, and the problem is, these formats cause Perl to core 
>dump. Here's an example format which causes the problem:
>
>format STDOUT=
>^^^^^^^
>$a{0},$a{1},$a{2},$a{3},$a{4},$a{5},$a{6}
>.

This is strange. Blows up on a current ActiveState Win32 build, too.
On the other hand, it does work fine on a vintage Perl 5.003 on HP/UX.

Of course, a really simple workaround would be just to use:

format STDOUT=
^||||||
join( '', @a )
 .

provided you switch a from a hash to an array. 

HTH,
-- 
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.


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

Date: 26 Jul 2001 04:16:36 -0700
From: rdeenen@mollymail.com (rolf deenen)
Subject: viewing input from a form
Message-Id: <5b51a4e6.0107260316.6744da4a@posting.google.com>

Hi there,

small question here. I'm fiddling around at the moment with cgi and
forms en i have the following question: My forms use the POST method
of sending data which is the fed into a certain script. But is it also
possible to print this input to my console so I can seen what data
enters the script?

Thanks in advance,

Rolf Deenen


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

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.  

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


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