[22513] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4734 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 20 09:06:20 2003

Date: Thu, 20 Mar 2003 06:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 20 Mar 2003     Volume: 10 Number: 4734

Today's topics:
        [:print:] difference with and without locale <krahnj@acm.org>
    Re: [:print:] difference with and without locale (Anno Siegel)
        array namen dynamisch generieren (=?ISO-8859-1?Q?Ulrich_G=F6dert?=)
    Re: array namen dynamisch generieren <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: array namen dynamisch generieren <josef.moellers@fujitsu-siemens.com>
    Re: array namen dynamisch generieren (Helgi Briem)
    Re: array namen dynamisch generieren <REMOVEsdnCAPS@comcast.net>
    Re: Can't access array element in Class::Struct structu (Anno Siegel)
    Re: Catching RST when using sysread and sockets (Villy Kruse)
        doubts on \n <fxn@hashref.com>
    Re: Find&Replace only in a certain scope (Anno Siegel)
        How can I....? (Cyber Scorpion)
    Re: How can I....? <noreply@gunnar.cc>
    Re: How can I....? <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Need a little help with a short script <tassilo.parseval@post.rwth-aachen.de>
    Re: Open file and print out contents from array (Tad McClellan)
    Re: Problem in conversion letter (W.J cnqin )
        Removing Blank Lines - should be simple <nospam@xx.com>
    Re: Removing Blank Lines - should be simple <josef.moellers@fujitsu-siemens.com>
    Re: Removing Blank Lines - should be simple <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Removing Blank Lines - should be simple <krahnj@acm.org>
    Re: Removing Blank Lines - should be simple <nospam@xx.com>
    Re: Removing Blank Lines - should be simple (Helgi Briem)
    Re: Removing Blank Lines - should be simple <josef.moellers@fujitsu-siemens.com>
    Re: Socket Problem In Perl <sfandino@yahoo.com>
    Re: Text::ParseWords or Text::CSV <josef.moellers@fujitsu-siemens.com>
        The impact of SSH. <pengtaoli@hotmail.com>
    Re: The impact of SSH. <dont@want.spam>
    Re: The impact of SSH. <vladimir@NoSpamPLZ.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 20 Mar 2003 10:26:24 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: [:print:] difference with and without locale
Message-Id: <3E799740.297A4FD6@acm.org>

This looks like a bug with [:print:].  Either "use locale" should be
printing "\t", "\n", "\f" and "\r" or without "use locale" it should not.


$ echo $LANG  
en_US
$ perl -Mlocale -le'
@x = map{$_=sprintf"%02X",ord} grep$_ lt" ", grep/[[:print:]]/, map chr,0..255; print"@x"'

$ perl -le'
@x = map{$_=sprintf"%02X",ord} grep$_ lt" ", grep/[[:print:]]/, map chr,0..255; print"@x"'
09 0A 0C 0D
$ perl -v

This is perl, v5.6.0 built for i586-linux

Copyright 1987-2000, Larry Wall


Does this do the same thing on newer versions, I only have 5.6.0 at the moment.



John
-- 
use Perl;
program
fulfillment


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

Date: 20 Mar 2003 10:50:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [:print:] difference with and without locale
Message-Id: <b5c6e2$gb5$1@mamenchi.zrz.TU-Berlin.DE>

John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> This looks like a bug with [:print:].  Either "use locale" should be
> printing "\t", "\n", "\f" and "\r" or without "use locale" it should not.
> 
> 
> $ echo $LANG  
> en_US
> $ perl -Mlocale -le'
> @x = map{$_=sprintf"%02X",ord} grep$_ lt" ", grep/[[:print:]]/, map
> chr,0..255; print"@x"'
> 
> $ perl -le'
> @x = map{$_=sprintf"%02X",ord} grep$_ lt" ", grep/[[:print:]]/, map
> chr,0..255; print"@x"'
> 09 0A 0C 0D
> $ perl -v
> 
> This is perl, v5.6.0 built for i586-linux
> 
> Copyright 1987-2000, Larry Wall
> 
> 
> Does this do the same thing on newer versions, I only have 5.6.0 at the moment.

Perl 5.8.0 prints nothing, independent of locale.

Anno


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

Date: 20 Mar 2003 02:46:53 -0800
From: google_groops@goedert.org (=?ISO-8859-1?Q?Ulrich_G=F6dert?=)
Subject: array namen dynamisch generieren
Message-Id: <fcb5da4a.0303200246.799aea53@posting.google.com>

Hallo,

ich bin auf der Suche nach einer Möglichkeit, array namen dynamisch
zur Laufzeit zu generieren. Dabei sollen per $t1=substr($var,1,1) und
einem festen Teil "foo" der Name zusammengesetzt werden. Das Ergebis
sollte ein @afoo, @bfoo, ... sein.Ein hash ist keine Lösung, da ich
die arrays mit Namen später brauche

[...]
foreach $werta (@afoo){ 
        [...]
}
foreach $wertb (@bfoo){ 
        [...]
}
[...]
Kann mir da jemand weiterhelfen? ich habe mich irgendwie verrannt und
komme auf keinen grünen Zweig.

DANKE!


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

Date: Thu, 20 Mar 2003 10:48:46 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: array namen dynamisch generieren
Message-Id: <Xns9344776376D57elhber1lidotechnet@62.89.127.66>

Ulrich Gödert wrote:

> Hallo,
> 
> ich bin auf der Suche nach einer Möglichkeit, array namen dynamisch
> zur Laufzeit zu generieren. Dabei sollen per $t1=substr($var,1,1) und
> einem festen Teil "foo" der Name zusammengesetzt werden. Das Ergebis
> sollte ein @afoo, @bfoo, ... sein.Ein hash ist keine Lösung, da ich
> die arrays mit Namen später brauche
> 
> [...]
> foreach $werta (@afoo){ 
>         [...]
> }
> foreach $wertb (@bfoo){ 
>         [...]
> }
> [...]
> Kann mir da jemand weiterhelfen? ich habe mich irgendwie verrannt und
> komme auf keinen grünen Zweig.
> 
> DANKE!
 

Ich bin ein Berliner.


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Thu, 20 Mar 2003 12:27:07 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: array namen dynamisch generieren
Message-Id: <3E79A58B.BC70D5F1@fujitsu-siemens.com>

Ulrich G=F6dert wrote:
> =

> Hallo,
> =

> ich bin auf der Suche nach einer M=F6glichkeit, array namen dynamisch
> zur Laufzeit zu generieren. Dabei sollen per $t1=3Dsubstr($var,1,1) und=

> einem festen Teil "foo" der Name zusammengesetzt werden. Das Ergebis
> sollte ein @afoo, @bfoo, ... sein.Ein hash ist keine L=F6sung, da ich
> die arrays mit Namen sp=E4ter brauche
> =

> [...]
> foreach $werta (@afoo){
>         [...]
> }
> foreach $wertb (@bfoo){
>         [...]
> }
> [...]
> Kann mir da jemand weiterhelfen? ich habe mich irgendwie verrannt und
> komme auf keinen gr=FCnen Zweig.

I'm from Paderborn (hi Bernard), but nonetheless B-{) Ulrich, this is
not de.comp.lang.perl.misc ...

The poster wishes to construct variable names from data. He claims that
he's unable to use hashes.

You might want to look at this construct:

	$variable =3D "ABC";
	$name =3D "variable";
	print ${$name}, "\n";

HTH,

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Thu, 20 Mar 2003 11:33:05 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: array namen dynamisch generieren
Message-Id: <3e79a5b9.3541315161@news.cis.dfn.de>

On Thu, 20 Mar 2003 12:27:07 +0100, Josef
=?iso-8859-1?Q?M=F6llers?=
<josef.moellers@fujitsu-siemens.com> wrote:

>Ulrich G=F6dert wrote:
>> ich bin auf der Suche nach einer M=F6glichkeit, array namen dynamisch
>> zur Laufzeit zu generieren. Dabei sollen per $t1=3Dsubstr($var,1,1) und=
>
>> einem festen Teil "foo" der Name zusammengesetzt werden. Das Ergebis
>> sollte ein @afoo, @bfoo, ... sein.Ein hash ist keine L=F6sung, da ich
>> die arrays mit Namen sp=E4ter brauche
>> =
>
>> [...]
>> foreach $werta (@afoo){
>>         [...]
>> }
>> foreach $wertb (@bfoo){
>>         [...]
>> }
>> [...]
>> Kann mir da jemand weiterhelfen? ich habe mich irgendwie verrannt und
>> komme auf keinen gr=FCnen Zweig.
>
>I'm from Paderborn (hi Bernard), but nonetheless B-{) Ulrich, this is
>not de.comp.lang.perl.misc ...
>
>The poster wishes to construct variable names from data. 

That's what I thought,  although my German is not quite
up to discussing programming.  Some might argue
that my English isn't either, but that's another matter.

>He claims that he's unable to use hashes.

Well, then he shouldn't use Perl.

He should read the following articles:

http://perl.plover.com/varvarname.html
http://perl.plover.com/varvarname2.html
http://perl.plover.com/varvarname3.html

And then use a hash.

To quote Tad:  "Well, stop wanting that!"
-- 
Regards, Helgi Briem
helgi AT decode DOT is


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

Date: Thu, 20 Mar 2003 08:01:08 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: array namen dynamisch generieren
Message-Id: <Xns93445BAD39885sdn.comcast@216.166.71.239>

Josef Möllers <josef.moellers@fujitsu-siemens.com> wrote in 
news:3E79A58B.BC70D5F1@fujitsu-siemens.com:

> The poster wishes to construct variable names from data. He claims that
> he's unable to use hashes.

That's pretty hard to believe.

-- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;


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

Date: 20 Mar 2003 11:52:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Can't access array element in Class::Struct structure
Message-Id: <b5ca2i$gb5$2@mamenchi.zrz.TU-Berlin.DE>

Carlton Brown <carltonbrown@hotmail.com> wrote in comp.lang.perl.misc:
> Problem:  Using a simple snippet of example code, I am unable to
> assign or access array attributes of a struct.   Scalars work fine.

[snip. most of this has been cleared up]

> print "His most famous alias is $him->aliases(0)\n";

This won't work under any Perl version.  Method calls don't interpolate.
Write it

    print "His most famous alias is ", $him->aliases(0), "\n";

Anno


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

Date: 20 Mar 2003 08:22:36 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Catching RST when using sysread and sockets
Message-Id: <slrnb7iuic.cpn.vek@station02.ohout.pharmapartners.nl>

On Wed, 19 Mar 2003 16:31:03 -0500,
    Ben Kennedy <bkennedy@hmsonline.com> wrote:


>
>"Scott McPheeters" <scottmc94@hotmail.com> wrote in message
>news:13b27267.0303180821.7eb2b4bf@posting.google.com...
>
>> My problem is every once in a while the tandem will send a RST (I see
>> the RST using a packet sniffer) and I can't seem to catch it.  My
>> sysread will just sit there looking for data that doesn't come.
>
>Perl has no knowledge whatsoever of the details of the interchange - it just
>sees a file descriptor it gets from the OS
>

I would expect, though, that perl would see an eof condition when the
remote end has shut down the connection.  If the remote end lost power
or otherwise got a kernel chrash, then the attempted read can wait for
ever.  To deal with that, the can_read method from IO::Select can
be quite useful.


Villy


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

Date: Thu, 20 Mar 2003 11:11:08 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: doubts on \n
Message-Id: <b5c7kb$lms$1@news.ya.com>

After reading perlport I have yet some doubts about \n. I think my basic
doubt is about the exact points where the conversion between logical and
real newlines is done, but I have a little mess in my mind so I'll just ask
some related questions instead, and see if I get the picture.

Assuming binmode off:

* Is length("\n") == 1 true in all platforms?

* Is (default) $/ eq "\n" true in all platforms?

* When is "\n" converted to "\015\012" under Windows?

* Is

     $whole_file = do { local $/; <FH> };
     $whole_file =~ s/\n//g;
     
  a portable way to delete newlines provided the newlines in the file under
  FH are the ones in that platform?
  
* If a script is running under Linux could the script know somehow it is
  reading a text file from, say, a fat32 partition? Does "portability" always
  imply the files being processed have the conventions of the system reported
  by $^O?


I am sorry I cannot think of a more concrete question that I knew in advance
it would answer all that.

-- fxn


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

Date: 20 Mar 2003 09:22:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Find&Replace only in a certain scope
Message-Id: <b5c18u$de8$1@mamenchi.zrz.TU-Berlin.DE>

Marek Stepanek  <mstep@t-online.de> wrote in comp.lang.perl.misc:
> On 19.03.2003 10:27 Uhr, in article b59d5u$ahu$1@mamenchi.zrz.TU-Berlin.DE,
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote:
> 
> 
> > 
> > Your problem isn't how to limit the effect of a text substitution to
> > part of a string.  That is trivial:
> > 
> >   substr( $str, $start, $length) =~ s///;
> > 
> > deals only with the substring and leaves other parts alone.  Your
> > problem is how to find the substring(s) you want to work on.  This
> > is where HTML parsing enters because regex matching just doesn't cut
> > it.
> > 
> > Anno
> 
> 
> Thank you Anno, and Tassilo,
> 
> finally some answers!

I am so glad you approve.

>                       But a little bit disappointing. I thought - I am only
> a Perl beginner - that the following should be possible:
> 
> look for _keyword_ 
> look behind the closest <table
> set the offset of it in a $beginning_variable
> look forward to the closest </table
> set it to the $end_variable
> replace all _0\d with _01 from $beginning_variable to $end_variable
> 
> ... the rest (the loop) would be easy. Even for me as a beginner.
> 
> so: is this not possible to set an offset to a variable an search between
> two positions ???

Of course it is possible, in multiple ways which have been pointed out.
However, as has also been pointed out, this is not the right way to do
it.  So it is unlikely that anyone will take the time to write up the
code for you.

> (I am already doubting about the power of Perl ... )

 ...won't work either.  We can live with your doubts.

Anno


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

Date: 20 Mar 2003 01:48:09 -0800
From: cyberscorpion@mail.bg (Cyber Scorpion)
Subject: How can I....?
Message-Id: <38d3b40.0303200148.378a978d@posting.google.com>

I want to compare 2 strings in case in-sensitive mode, but the strings
contain cyrillic characters (ascii code > 127 and < 255) and the
standart way does not work, i.e. the following code:

if ($sdata =~ /$rdata/i)
{
 ....
}

doesn't work. How can I do this? Please advice!
Thanks!


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

Date: Thu, 20 Mar 2003 10:56:13 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How can I....?
Message-Id: <b5c3m2$28cv7a$1@ID-184292.news.dfncis.de>

Cyber Scorpion wrote:
> I want to compare 2 strings in case in-sensitive mode, but the
> strings contain cyrillic characters

     http://www.perldoc.com/perl5.8.0/pod/perllocale.html

/ Gunnar

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



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

Date: Thu, 20 Mar 2003 10:05:42 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: How can I....?
Message-Id: <Xns93447016EF09Eelhber1lidotechnet@62.89.127.66>

Cyber Scorpion wrote:

> I want to compare 2 strings in case in-sensitive mode, but the strings
> contain cyrillic characters (ascii code > 127 and < 255) and the
> standart way does not work, i.e. the following code:
> 
> if ($sdata =~ /$rdata/i)
> {
> ....
> }
> 
> doesn't work. How can I do this? Please advice!


   perldoc perllocale


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: 20 Mar 2003 08:26:10 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Need a little help with a short script
Message-Id: <b5btv2$aaq$1@nets3.rz.RWTH-Aachen.DE>

Also sprach HKVandal:

> Hi trying to make my first productive script, it (in theory)renames
> file extensions in win32, script is below

Did you really write it without any indenting? This is extremely hard to
read. I added the indenting to make it more pleasing to the eye:

> print "Type in name of Directory, ie. C:\\music\\\n";
> chomp($dirname=<STDIN>);
> print "Type in name of extension to replace ie. mp3 (no period)";
> chomp($old=<STDIN>);
> print "Type in name of the new extension ie. mpg";
> chomp($new=<STDIN>);
> opendir (DIR, $dirname) or die "can't open dir $!";
> while(defined($file=readdir(DIR))){
>     $old_file=$file;
>     if($file=~/.*\.(.*)/){
>         $currext=$1;
>         if($currext=$old){

This line is wrong. The if-condition is always true. You do not make a
comparison but instead assign the value of $old to $currext. Since $old
is true (well, most of the time depending on the user's input), $currext
is true and therefore the expression evaluates to true. It should read:

    if ($currext eq $old) {

'eq' tests for string-equality. If you want to test numbers, use '=='.

>             $file=~/(.*)\..*/;
>             $currfile=$1;
>             $new_file=$currfile . "\." . $new;
>             rename ($old_file, $new_file) or die "$!";

Second mistake here. You open the directory $dirname. readdir() returns
the entries of the directory without the preceeding path. So you either
have to prepend $dirname yourself or chdir() to this directory in order
to make this work. Like that:

    rename "$dirname/$old_file, "$dirname/$new_file" or die $!;

>         }
>     }
> }
> closedir(DIR);

> I get the following error when I run it
> 
> Permission denied at c:\docs\ext.pl line 16, <STDIN> line 3.

Odd, I would have expected a different message here (something about not
finding the file or so).

Anyway, your script is too complicated for the given task. The logic is
hard to follow since you are using too many variables. Here's a cleaner
version that hopefully even a beginner could understand:

    use strict;
    use warnings;

    print "Directory:\n";
    chomp( my $dir = <STDIN> );

    print "Old extension:\n";
    chomp( my $oldex = <STDIN> );

    print "New extension:\n";
    chomp( my $newex = <STDIN> );

    opendir DIR, $dir or die "Error opening $dir: $!";
    
    while (my $entry = readdir DIR) {
    
        # skip if file does not end on ".$oldex"
        next if $entry !~ /\.$oldex$/;
        
        my $newfile = $entry;
        # replace old extension with new one
        $newfile =~ s/$oldex$/$newex/;
        
        print "$dir/$entry => $dir/$newfile\n"; # some debug output
        rename "$dir/$entry", "$dir/$newfile" or die $!;
    }
    
    closedir DIR;
        
In the above script there'll be a few things you probably don't yet
know, notably the 'use strict' line and the my() keyword used before new
variables. The above script also runs if you leave off the strict-thing
and scratch all my()s at the same time. See below.

> Any help is greatly appreciated

Since you are very new to Perl you should have a look at
http://learn.perl.org/. There you can subscribe to the beginner's
mailing-list which for the moment might be a more suitable place for
you. It's also a good place to find out about this magical strict/my()
issue which you should do immediately. The reason for this redirection
is that this group actually has some posting-guidelines that would
require you to always use strict in your programs if you intend to post
them here and request help. You can find these posting-guidelines at

    http://mail.augustmail.com/~tadmc/clpmisc.shtml

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 20 Mar 2003 06:42:13 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Open file and print out contents from array
Message-Id: <slrnb7jdp5.65e.tadmc@magna.augustmail.com>

Jacques Veldhuijzen <veld@interparts-cp.nl> wrote:

> 	open (IN, "$text_url"); 
                  ^         ^ those quotes do not do anything
                  ^         ^ so they should not be there


You should always, yes *always*, check the return value from open():

   open (IN, $text_url) or die "could not open '$text_url'  $!";


>         print MAIL @lines;
> has no effect at all.


Then @lines is empty, probably because your open() failed.

If you had checked open()'s return value, you would know what is wrong.

If you had enabled warnings, you would have known that something was
wrong on the <IN> line.

You should always enable warnings when developing Perl code!



open() works on *files* not URLs. If $text_url is really a URL
that you want to fetch, then see the Perl FAQ:

   perldoc -q fetch

      "How do I fetch an HTML file?"


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 20 Mar 2003 16:31:41 +0800
From: qin@freebsd.lzu.edu.cn (W.J cnqin )
Subject: Re: Problem in conversion letter
Message-Id: <86isuewiaa.fsf@freebsd.lzu.edu.cn>

Bryan Krone <cbk047@email.mot.com> writes:

[..]
> > > > Thanx,
> > 
> > Shlomit

Yes , it is true. But when I use oct to convert binary data to correspo-
nding decimal-based number, it fails. I reviewed the perldoc -f oct ,
and i have tried hex-to-deci and it is ok. This is my revised program:

foreach (@list){
    print "Binary code : $_ \n";
    $_ = oct("0b".$_);          # convert binary data to decimal-based ,
                                # but $_ is 0 ????
    my $char = pack("c1", $_);
    print "Char code   : $char \n";    
}





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

Date: Thu, 20 Mar 2003 01:16:40 -0800
From: Eric <nospam@xx.com>
Subject: Removing Blank Lines - should be simple
Message-Id: <3E7986F7.C5BCF464@xx.com>

I've checked 2 Perl books, my Perl Desktop Reference and perlre but
after several hours still can't figure out how to remove blank lines.

The other lines I need to remove from some .php scripts get axed or
cleaned up okay.  I've tried several things but they just don't
work...even figured if I matched on 70 whitespaces that might do it, but
no dice.

Here is the pertinent snippet from my script:

while ($line = <INFILE>)				
{
  chomp($line);
  $line =~ s/^\s+//g;  #whitespace cleanup on front of lines
  &write2outfile unless $line =~ m/ +\n/ || $line =~ m/\s{70}/ ||
     $line =~ m/^\// || $line =~ m/^\s+\*|^\*/;
}

Thanks to anyone who can help.

Eric


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

Date: Thu, 20 Mar 2003 10:27:36 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Removing Blank Lines - should be simple
Message-Id: <3E798988.C245E830@fujitsu-siemens.com>

Eric wrote:
> =

> I've checked 2 Perl books, my Perl Desktop Reference and perlre but
> after several hours still can't figure out how to remove blank lines.
> =

> The other lines I need to remove from some .php scripts get axed or
> cleaned up okay.  I've tried several things but they just don't
> work...even figured if I matched on 70 whitespaces that might do it, bu=
t
> no dice.
> =

> Here is the pertinent snippet from my script:
> =

> while ($line =3D <INFILE>)
> {
>   chomp($line);
>   $line =3D~ s/^\s+//g;  #whitespace cleanup on front of lines
>   & unless $line =3D~ m/ +\n/ || $line =3D~ m/\s{70}/ ||
>      $line =3D~ m/^\// || $line =3D~ m/^\s+\*|^\*/;
> }
> =

> Thanks to anyone who can help.

What is a blank line? A blank line is a line which contains zero or more
blanks. The pattern which matches this is /^\s*$/.

while (<INFILE>) {
    chomp;
    next if /^\s*$/;
    # lie is not blank
}

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Thu, 20 Mar 2003 09:28:12 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Removing Blank Lines - should be simple
Message-Id: <Xns934469BB0BBB0elhber1lidotechnet@62.89.127.66>

Eric wrote:

> I've checked 2 Perl books, my Perl Desktop Reference and perlre but
> after several hours still can't figure out how to remove blank lines.
> 
> The other lines I need to remove from some .php scripts get axed or
> cleaned up okay.  I've tried several things but they just don't
> work...even figured if I matched on 70 whitespaces that might do it, but
> no dice.
> 
> Here is the pertinent snippet from my script:
> 

 while ($line = <INFILE>) {
   next if $line =~ m/^\s*$/;
   chomp($line);
   $line =~ s/^\s+//g;  #whitespace cleanup on front of lines
   &write2outfile;
 }


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Thu, 20 Mar 2003 09:29:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Removing Blank Lines - should be simple
Message-Id: <3E7989FE.92395526@acm.org>

Eric wrote:
> 
> I've checked 2 Perl books, my Perl Desktop Reference and perlre but
> after several hours still can't figure out how to remove blank lines.
> 
> The other lines I need to remove from some .php scripts get axed or
> cleaned up okay.  I've tried several things but they just don't
> work...even figured if I matched on 70 whitespaces that might do it, but
> no dice.
> 
> Here is the pertinent snippet from my script:
> 
> while ($line = <INFILE>)
> {

    # skip line with only whitespace characters
    next unless $line =~ /\S/;


>   chomp($line);
>   $line =~ s/^\s+//g;  #whitespace cleanup on front of lines
>   &write2outfile unless $line =~ m/ +\n/ || $line =~ m/\s{70}/ ||
>      $line =~ m/^\// || $line =~ m/^\s+\*|^\*/;
> }


John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 20 Mar 2003 01:34:56 -0800
From: Eric <nospam@xx.com>
Subject: Re: Removing Blank Lines - should be simple
Message-Id: <3E798B40.56E8B6F6@xx.com>

Josef & Bernard were both kind enough to reply:

RE:
> The pattern which matches this is /^\s*$/

I just don't know why I could not find this in any of the references I
checked. Umh, I had also tried /^\s+$/ but that didn't work ;-(

Thank you, thank you, thank you both:  /^\s*$/ worked like a charm ...
and now I can finally go to bed (1:30AM local).

Regards,

Eric


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

Date: Thu, 20 Mar 2003 10:19:27 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Removing Blank Lines - should be simple
Message-Id: <3e79956c.3537142291@news.cis.dfn.de>

On Thu, 20 Mar 2003 01:34:56 -0800, Eric <nospam@xx.com>
wrote:

>Josef & Bernard were both kind enough to reply:
>
>RE:
>> The pattern which matches this is /^\s*$/
>
>I just don't know why I could not find this in any of the references I
>checked. Umh, I had also tried /^\s+$/ but that didn't work ;-(

It should.  I always use it. Quick test:

while (<DATA>){ next if  /^\s+$/; print; }
__END__
line one

line two
line three

Produces:
line one
line two
line three
-- 
Regards, Helgi Briem
helgi AT decode DOT is


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

Date: Thu, 20 Mar 2003 11:48:26 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Removing Blank Lines - should be simple
Message-Id: <3E799C7A.C1F205C2@fujitsu-siemens.com>

Eric wrote:
> =

> Josef & Bernard were both kind enough to reply:
> =

> RE:
> > The pattern which matches this is /^\s*$/
> =

> I just don't know why I could not find this in any of the references I
> checked. Umh, I had also tried /^\s+$/ but that didn't work ;-(

It depends on whether you use it before or after a chomp! Your pattern
requires at least one space character! /^\s*$/ requires zero or more
space characters.

If you use it before a chomp, the line terminator(s) will fullfill the
"at least one space character" condition and you'll get a match.
If you use it after a chomp, a completely empty line will not cause a
match because there is absolutely nothing which matches "at least one".

while (<INFILE>) {
    next if /^\s+$/;	# This could also be ^\s*$
    chomp;

or

while (<INFILE>) {
    chomp;
    next if  /^\s*$/;	# This must not be ^\s+$

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Thu, 20 Mar 2003 10:24:30 +0000
From: =?ISO-8859-1?Q?Salvador_Fandi=F1o_Garc=EDa?= <sfandino@yahoo.com>
To: Ryan Ritten <sparticusREMOVE@thesparticusarena.com>
Subject: Re: Socket Problem In Perl
Message-Id: <3E7996DE.9090206@yahoo.com>

Ryan Ritten wrote:
> I wrote a little client/server in perl using sockets.  Everything
> works fine if the client exits normally ... the server notices that
> the socket is done and closes it.  But if the client dies abnormally
> (ie. computer freezes... etc) the server doesn't notice that the
> client is gone and keeps the socket open...
> 
> am I doing something wrong?  Is this was it supposed to happen or is
> there a quick fix for it.  I'd paste my code here but it's part of a
> game I've made and is huge.

use the SO_KEEPALIVE option for your server sockets:

   setsockopt $socket, SOL_SOCKET, SO_KEEPALIVE, 1

it will make your OS test the connection from time to time to see if the 
other end is still alive.

Bye,

   - Salva



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

Date: Thu, 20 Mar 2003 09:19:23 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Text::ParseWords or Text::CSV
Message-Id: <3E79798B.F35E3939@fujitsu-siemens.com>

david wrote:
> =

> Does anyone have experience with either of these two modules? Im
> trying to figure out how to parse a comma delimited file, but the
> problem is certain fields also have commas so when the file is
> exported to text format, of course it now looks like it has more
> fields. I want to remove the comma's from the fields that have them:
> =

> dlepage,engineer,mn,"infrastrucuture",6-5-02
> aidan,support,va,"infrastructure,engineering", 3-1-96
> =

> I put quotes around the actual 'field 3', but the actual file I want
> to work on does NOT have the quotes:
> =

> dlepage,engineer,mn,infrastrucuture,6-5-02
> aidan,support,va,infrastructure,engineering, 3-1-96
> =

> i.e.
> field0=3Daidan
> field1=3Dsupport
> field2=3Dva
> field3=3Dinfrastructure,engineering
> field4=3D3-1-96
> =

> So far im stuck on the basics of either of these modules, and first of
> all, whether any of these are the right ones to use.
> perl -w
> use strict;
> use Text::ParseWords
> open (IN, "<infile.txt") || die "Cannot open $!\n";
> =

> my $line;
> while ($line =3D <IN> ) {
>          @words =3D &parse_line(/,/, 0, $line);
>          print $line
>  }
> =

> This is very simplified code because I could not get any variations on
> this theme to work.
> I think if possible, I should be parsing by comma's up to and
> including 0-2 and take whatever is in field 3 and remove the comma if
> present. Any suggestions?

I assume that only field3 will have commas? Otherwise it's ambiguous.

How about: split by the comma, take the first three fields and the last
field and combine the rest back using commas:

while (<IN>) {
    @fields =3D split(/,/);
    $field0 =3D shift @fields;
    $field1 =3D shift @fields;
    $field2 =3D shift @fields;
    $field4 =3D pop @fields;
    $field3 =3D join ",", @fields;
}

TMTOWTDI, e.g. using a slice:

while (<IN>) {
    @fields =3D split(/,/);
    $field0 =3D $fields[0];
    $field1 =3D $fields[1];
    $field2 =3D $fields[2];
    $field3 =3D join(",", @fields[3 .. ($#fields-1)]);
    $field4 =3D $fields[$#fields];
}

Note that the data you gave will result in field4 having a leading
blank.

HTH,

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Thu, 20 Mar 2003 17:21:37 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: The impact of SSH.
Message-Id: <b5c177$btg@netnews.proxy.lucent.com>

Hello All,

I used Net::FTP in my perl program to transfer files between
Solaris servers.  Now we have the plan to use SSH between
these Solaris hosts. So can anyone tell me if it will impact
my original program?

Thank you in advance!

Franklin




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

Date: Thu, 20 Mar 2003 09:48:48 +0000
From: Chris Lowth <dont@want.spam>
Subject: Re: The impact of SSH.
Message-Id: <99gea.192$OW2.28487@newsfep1-win.server.ntli.net>

Franklin Lee wrote:

> Hello All,
> 
> I used Net::FTP in my perl program to transfer files between
> Solaris servers.  Now we have the plan to use SSH between
> these Solaris hosts. So can anyone tell me if it will impact
> my original program?
> 
> Thank you in advance!
> 
> Franklin

That very much depends on how the SSH is setup. I assume you are proposing 
to use tunnels - if so, then its probably just a matter of changing the IP 
address and port number that your script connects to. You may need to use 
"PASV" mode as well if only ports 21 and 20 are tunneled.

It sounds as if SSH is a new area to you - can I suggest that you read up on 
in. The manual pages are quite good, and the OpenSSH web site has lots of 
useful info.

It's worth noting that there are SSH alternatives to FTP - namely SFTP and 
SCP - it might be worth considering them instead of FTP.

Chris

-- 
Real address: chris at lowth dot sea oh em.
For free GPL e-mail virus blockade ...
  http://protector.sourceforge.net


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

Date: Thu, 20 Mar 2003 13:06:24 GMT
From: "Vladimir P." <vladimir@NoSpamPLZ.net>
Subject: Re: The impact of SSH.
Message-Id: <k1jea.26$Xy5.5108@wagner.videotron.net>

On Thu, 20 Mar 2003 17:21:37 +0800, Franklin Lee wrote:
> Hello All,
> 
> I used Net::FTP in my perl program to transfer files between
> Solaris servers.  Now we have the plan to use SSH between
> these Solaris hosts. So can anyone tell me if it will impact
> my original program?
> 
> Thank you in advance!
> 
> Franklin

There should be very little impact esp if you use Net::SFTP module.
Use CPAN to install it ('perl -MCPAN -e shell' and install Net::SFTP) - 
Net::SFTP depends on Net::SSH::Perl, which in turn requires bunch
of other modules. 



-- 
 .signature: No such file or directory


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

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


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