[19394] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1589 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 22 18:05:44 2001

Date: Wed, 22 Aug 2001 15:05:13 -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: <998517913-v10-i1589@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 22 Aug 2001     Volume: 10 Number: 1589

Today's topics:
    Re: 'filtering' a hash (Abigail)
    Re: a Call to exec several bat files (Malcolm Dew-Jones)
        Accessing anonymous hash inside array?? <miscellaneousemail@yahoo.com>
    Re: Accessing anonymous hash inside array?? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Accessing anonymous hash inside array?? <miscellaneousemail@yahoo.com>
    Re: Accessing anonymous hash inside array?? (David Wall)
    Re: annoying habit of perl 5 in freebsd <ilya@martynov.org>
    Re: annoying habit of perl 5 in freebsd (Anno Siegel)
    Re: annoying habit of perl 5 in freebsd <ilya@martynov.org>
    Re: arrays question <ren@tivoli.com>
    Re: Caching information about IP subnets <gfk@spamcop.net>
    Re: Calling severl bat files from perl script <somewhere@in.paradise.net>
    Re: Comma's at end of list can break program?? (Abigail)
    Re: Comma's at end of list can break program?? <ren@tivoli.com>
    Re: days since 1/1/1970 (Abigail)
    Re: days since 1/1/1970 <jurgenex@hotmail.com>
        Directory listing order <gfk@spamcop.net>
    Re: Directory listing order (John J. Trammell)
    Re: error handling question ;O) <gnarinn@hotmail.com>
        Error in a if.elsif construction (Nomade)
    Re: Error in a if.elsif construction <Tassilo.Parseval@post.rwth-aachen.de>
        Executing DEL and UPDT PL/SQL stored procedures from PE (GC)
    Re: Extracting Blocks of text (Abigail)
    Re: Help w/grep <gnarinn@hotmail.com>
    Re: How do I sort a 2D-array by three different columns <gnarinn@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Aug 2001 19:24:27 GMT
From: abigail@foad.org (Abigail)
Subject: Re: 'filtering' a hash
Message-Id: <slrn9o81nn.6m2.abigail@alexandra.xs4all.nl>

Anne Janse (A.S.Janse@azu.nl) wrote on MMCMXIII September MCMXCIII in
<URL:news:Pine.GSO.4.30.0108221304320.14748-100000@dizzy.azu.nl>:
## Hi all,
## 
## I've got a hash %hash and an array @array
## and I'd like to make a new hash %newhash that contains only those
## $key-$value pairs from %hash of which there is no $key in @array.
## 
## In other words, I'd like to throw away all $key-$value pairs
## from %hash of which $key is in @array.
## 
## How can I do this? The problem doesn't look too hard, but my perl
## experience is quite limited..


Two ways:

    my %newhash = %hash;
    delete @newhash {@array};


    my %temp = map {$_ => 1} @array;
    my @temp = grep {!$temp {$_}} keys %hash;
    my %newhash;
    @newhash {@temp} = @hash {@temp};



Abigail
-- 
$_ = "\112\165\163\1648\141\156\157\164\150\145\1628\120\145"
   . "\162\1548\110\141\143\153\145\162\0128\177"  and &japh;
sub japh {print "@_" and return if pop; split /\d/ and &japh}


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

Date: 22 Aug 2001 11:11:04 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: a Call to exec several bat files
Message-Id: <3b83f5b8@news.victoria.tc.ca>

Vic Antillon (70262.1046@compuserve.com) wrote:
: I need to be able to call a number of '.bat' files from a Perl script,
: one after the other, without waiting for the '.bat' files to return
: (since several of them run indefinitely). The 'exec' and 'system'
: functions don't seem to return unless the '.bat' file completes, so
: typically the first 2 will run, but the 2nd never returns so the
: subsequent 8 '.bat' files are never called.

How about 'start'? (available in CMD.EXE).  I think it has options to run
a program concurrently.  Start has various other options as well.

(untested)

#!perl
system("cmd.exe /c start /-start-options- the_bat_file.bat");






--
Want to access the command line of your CGI account?  Need to debug your
installed CGI scripts?  Transfer and edit files right from your browser? 

What you need is "ispy.cgi" - visit http://nisoftware.com/ispy.cgi


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

Date: Wed, 22 Aug 2001 20:48:41 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Accessing anonymous hash inside array??
Message-Id: <MPG.15edc86b4ed98cab98978b@news.edmonton.telusplanet.net>

Hi everyone,  

I was wondering if anyone could comment on some of the statements in the 
following code snippet where it says...

#<<---- DIRECT ACCESS??
  Is there a way to access the keys in the anonymous hash inside the 
  array with something like: foreach my $key (keys %{$data[0]} { 
  instead of what I have??

#<<---- LESS SYMBOLS, CLEARER??
  Is there a way to use cleaner and clearer symbology??

#<<---- NON-REPITITION OF $hashref->{$key}??
  Is there a way to use the ? : construct such that on true it 
  works as expected without having to re-type the true value?

The code:

#!/usr/bin/perl -WT 

my @data = (
 { address => 'jack@ardvark.com', 
   name    => 'Jack',
   date    => '020010812 18:34', 
   country => 'Canada', 
   city    => undef, 
   wanna   =>'Yes'},
);

my $hashref = \%{$data[0]};
# print all items in anonymous that have defined values.
foreach my $key (keys %$hashref) { #<<---- DIRECT ACCESS??
  print "$data[0]{$key}\n" if $data[0]{$key};
}  
print_all(\%{$data[0]});  #<<---- LESS SYMBOLS, CLEARER??

sub print_all
{
  my ($hashref) = @_;
  foreach my $key (keys %$hashref) {
    #<---- NON-REPITITION OF $hashref->{$key}??
    printf "%15s => %-30s\n", $key, $hashref->{$key} ? $hashref->{$key} : 
"undefined";
  }
}

Thanks.

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so please don't 
subscribe.  Thanks.


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

Date: Wed, 22 Aug 2001 23:32:00 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Accessing anonymous hash inside array??
Message-Id: <3B8424D0.4000706@post.rwth-aachen.de>

Carlos C. Gonzalez wrote:

> Hi everyone,  
> 
> I was wondering if anyone could comment on some of the statements in the 
> following code snippet where it says...

> The code:
> 
> #!/usr/bin/perl -WT 
> 
> my @data = (
>  { address => 'jack@ardvark.com', 
>    name    => 'Jack',
>    date    => '020010812 18:34', 
>    country => 'Canada', 
>    city    => undef, 
>    wanna   =>'Yes'},
> );
> 
> my $hashref = \%{$data[0]};

my $hashref = $data[0]; # it is already a hash-ref

> # print all items in anonymous that have defined values.
> foreach my $key (keys %$hashref) { #<<---- DIRECT ACCESS??
>   print "$data[0]{$key}\n" if $data[0]{$key};

You might try to be more consistent in your notation. Further below you 
write '$hashref->{key}'. So why not $data[0]->{key} as well? This is 
slightly more typing, but more eyefriendly in my eyes.

> }  
> print_all(\%{$data[0]});  #<<---- LESS SYMBOLS, CLEARER??

Well, again:
print_all($data[0]);

You are always dereferencing a hash and immediately after that 
referencing it again.

> 
> sub print_all
> {
>   my ($hashref) = @_;
>   foreach my $key (keys %$hashref) {
>     #<---- NON-REPITITION OF $hashref->{$key}??
>     printf "%15s => %-30s\n", $key, $hashref->{$key} ? $hashref->{$key} : 
> "undefined";

This here is ok, quite short and idiomatic.

Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Wed, 22 Aug 2001 21:43:23 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Accessing anonymous hash inside array??
Message-Id: <MPG.15edd549bda2063a98978c@news.edmonton.telusplanet.net>

Tassilo von Parseval at Tassilo.Parseval@post.rwth-aachen.de said...

> You are always dereferencing a hash and immediately after that 
> referencing it again.

Thanks bunches Tassilo.  I am still working my way through creating and 
using references so there will be some of this in my code.  Once I get 
the basic way to create and use these things down pat I can duplicate 
what I learn in the rest of my code.  

Excellent suggestions Tassilo.  Just what I was hoping for.  

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so please don't 
subscribe.  Thanks.


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

Date: Wed, 22 Aug 2001 22:01:44 -0000
From: darkon@one.net (David Wall)
Subject: Re: Accessing anonymous hash inside array??
Message-Id: <Xns9105B6EDB506Ddarkononenet@207.126.101.97>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote on 22 Aug 2001:

> #!/usr/bin/perl -WT 
> 
> my @data = (
>  { address => 'jack@ardvark.com', 
>    name    => 'Jack',
>    date    => '020010812 18:34', 
>    country => 'Canada', 
>    city    => undef, 
>    wanna   =>'Yes'},
> );
> 
[snip wanting clean ways to print the contents of an element of @data
 -- plus Tassilo von Parseval already commented on your code.]


If I were printing all of @data, didn't care about the order of the keys, I 
might do something like this:

foreach my $record (@data) {
    while ( my ($field, $value) = each %$record ) {
        print $field, ' => ', $value || 'undefined';
    }
    print "\n";
}

I'm not sure if that looks any cleaner to you, but I like it.  :-)

What if a value in the hash is defined but false?  A value of 0 might mean 
something very different from an undefined value.  

-- 
David Wall
darkon@one.net


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

Date: 22 Aug 2001 22:12:21 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: annoying habit of perl 5 in freebsd
Message-Id: <877kvwklq2.fsf@abra.ru>


JF> It seems that Perl on Freebsd (4.3) has this annoying habit:
JF> in the following environment:
JF> print "x";
JF> sleep 5;
JF> print "y";

Perl by default buffers output (and it is not freebsd specific). So
unless buffer is overflowed or string has newline char print will not
print anything.

You need to turn on non-buffered output:

$| = 1;

See 'perldoc perlvar' for description of variable $|;

JF> Perl will sleep 5 seconds, THEN print 'x' and 'y'. Also, where flock is
JF> concerned":
JF> open (infile,'>>file.txt');
JF> flock (infile,2) || die "cannot get lock!";

JF> Perl will always complain of trying to get a lock on a close file handle.
JF> this suggests that it is trying to flock BEFORE the open command.

It is looks like open haven't opened file for some reason. Always
check return value from open:

open (infile,'>>file.txt') or die "Can't open file: $!";

Probably permissions problem.

JF> I've not been able to find any documentation of this behaviour
JF> anywhere on the Internet. if anyone can suggest a workaround,
JF> please advise!

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| 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: 22 Aug 2001 18:25:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: annoying habit of perl 5 in freebsd
Message-Id: <9m0teu$9vm$2@mamenchi.zrz.TU-Berlin.DE>

According to Ilya Martynov  <ilya@martynov.org>:

> You need to turn on non-buffered output:
> 
> $| = 1;

Small correction here:  You don't make output unbuffered, you turn on
auto-flushing, that is, buffers are flushed on each print.  You keep
using the same buffering (though probably less of it).

Anno


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

Date: 22 Aug 2001 22:40:35 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: annoying habit of perl 5 in freebsd
Message-Id: <871ym4kkf0.fsf@abra.ru>

>>>>> On 22 Aug 2001 18:25:34 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) said:

AS> According to Ilya Martynov  <ilya@martynov.org>:
>> You need to turn on non-buffered output:
>> 
>> $| = 1;

AS> Small correction here:  You don't make output unbuffered, you turn on
AS> auto-flushing, that is, buffers are flushed on each print.  You keep
AS> using the same buffering (though probably less of it).

Thanks for correction. I selected incorect terms.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| 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: 22 Aug 2001 14:00:49 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: arrays question
Message-Id: <m3zo8r9axq.fsf@dhcp9-161.support.tivoli.com>

On Wed, 22 Aug 2001, CalinG@cfgroup.ca wrote:

>     How could I place 2(for ex. @numbers and @dates) or more arrays
>     together in a file, array 1 items would go on first row, array 2
>     items would go on second, etc. separated by comma,
>     consecutively?  Thanks a lot, Calin

I'm going to take a guess that despite the way your question reads you
actually want to interleave the values from the two arrays.  That is,
if you have:

@numbers = (1, 2, 3, 4);
@dates   = qw(monday tuesday wednesday thursday);

then you want the output to be:

1,monday
2,tuesday
3,wednesday
4,thursday


If that is correct, then you could use something like:

  die "Aborting: \@numbers and \@dates are not the same size!\n"
    unless @numbers == @dates;
  for (0..$#numbers) {
    print "$numbers[$_],$dates[$_]\n";
  }


However, you would probably be better off using a different data
structure rather than keeping parallel arrays  (see perldsc(1)).

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 22 Aug 2001 17:09:25 -0400
From: Guillaume Filion <gfk@spamcop.net>
Subject: Re: Caching information about IP subnets
Message-Id: <gfk-EE8155.17092522082001@news.videotron.net>

In article <Jhag7.11783$an2.250170@nnrp1.ptd.net>,
 doctor@ptd.net (Sargon) wrote:

> This may or not fall into a question that I have regarding subnets.
> 
> Currently I am working on a program that dumps information from a database 
> into files that another program needs to read. Anyway, I am stuck at the 
> subnet point of the programs.
> 
> I need to create an entry in each file called NetBlock. The netblock contains 
> the range of IP's an user has assigned to them.
> 
> Example:
> 
> Customer A has 192.68.0.0 - 192.68.0.7
> 
> This would be a /29
> I need my program to take 192.68.0.0 - 192.68.0.7 and create this output
> 
> NetBlock = 192.68.0.0/29
> 
> I am not sure what the simplicy way to accomplish this would be.

Pretty easy using module Net::IP :
----
use Net::IP;

my $ip = new IP ('192.68.0.0 - 192.68.0.7') or die (Net::IP::Error());
print "Subnet (CIDR notation): ".$ip->ip()."/".$ip->prefixlen()."\n";
----

Hope this helps,
GFK's


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

Date: Thu, 23 Aug 2001 07:49:11 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Calling severl bat files from perl script
Message-Id: <EOVg7.12$A11.106601@news.interact.net.au>


"Vic Antillon" <70262.1046@compuserve.com> wrote in message
news:3b83d926.1850921@news.compuserve.com...
> I need to be able to call a number of '.bat' files from a Perl script,
> one after the other, without waiting for the '.bat' files to return
> (since several of them run indefinitely). The 'exec' and 'system'
> functions don't seem to return unless the '.bat' file completes, so
> typically the first 2 will run, but the 2nd never returns so the
> subsequent 8 '.bat' files are never called.
>
> Any ideas? If 'fork()' is the answer, please send an example snippet
> of code, since I've never used 'fork()' before and don't know how to
> set it up.

Please do not post the same question, particularly with different subject
lines.




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

Date: 22 Aug 2001 19:45:35 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Comma's at end of list can break program??
Message-Id: <slrn9o82vb.6m2.abigail@alexandra.xs4all.nl>

Benjamin Goldberg (goldbb2@earthlink.net) wrote on MMCMXIII September
MCMXCIII in <URL:news:3B833DBE.D4F308FE@earthlink.net>:
:} Uri Guttman wrote:
:} [snip]
:} > if you heeded tom's advice here (and most others concur with it), the
:} > last list entry would have a , after it. a comma is needed between
:} > every pair of items in a list but with perl it is ok to put a
:} > superfluous comma after the last item.in many languages, the extra
:} > comma there is actually illegal. so by always ending the last element
:} > with a comma, you don't have to worry as much about noticing if a
:} > comma is missing when editing the list.
:} 
:} Although this isn't really related to defensive programming, there are
:} occasions when you want to write code which generates code, and perl's
:} allowing an extra comma makes life easier.  In these cases, particularly
:} in writing the contents of a list with a for or while loop, it is *much*
:} simpler to simply print a comma after every item, than to have to check
:} whether this is the last item to see if you need a comma.
:} 
:} eg:
:} print "my \@list = (\n";
:} print "\t$_,\n" while defined $_ = gen_next_item;
:} print ");\n";
:} 
:} If perl didn't allow the extra comma at the end of the list, this would
:} have to be something like:
:} 
:} print "my \@list = (\n";
:} if( defined $_ = gen_next_item ) {
:} 	print "\t$_";
:} 	print ",\n\t$_" while defined $_ = gen_next_item;
:} 	print "\n";
:} }
:} print ");\n";

Not at all! Let's assume a context sensitive gen_next_item, returning
all the items in list context.

    {   local $";
        print <<EOT;
        my \@list = (
        @{[map {"\t$_,\n"} gen_next_item]}
        );
    EOT
    }

:} Which is less clear and less pretty.


It even gets better if you don't care for that extra white space:

    {   local $" = ",";
        print "\@list = (@{[gen_next_item]});"
    }


Much cleaner, and no trailing comma!



Abigail
-- 
CHECK {print "another "}  #  A pair of quarreling
END   {print "Hacker\n"}  #  warriors. A mosquito
INIT  {print "Perl "   }  #  crawls in an elm.
BEGIN {print "Just "   }


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

Date: 22 Aug 2001 13:38:43 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Comma's at end of list can break program??
Message-Id: <m38zgc9byk.fsf@dhcp9-161.support.tivoli.com>

On Wed, 22 Aug 2001, goldbb2@earthlink.net wrote:

> If perl didn't allow the extra comma at the end of the list, this
> would have to be something like:
> 
> print "my \@list = (\n";
> if( defined $_ = gen_next_item ) {
> 	print "\t$_";
> 	print ",\n\t$_" while defined $_ = gen_next_item;
> 	print "\n";
> }
> print ");\n";

Not that it really matters, but an alternative to this (assuming
gen_next_item stays undefined once it becomes undefined) is:

  print "my \@list = (";
  print "\n\t$_" if defined($_ = gen_next_item);
  print ",\n\t$_" while defined($_ = gen_next_item);
  print "\n);\n";

As a unary operator, defined binds more tightly than assignment, so
those parens are actually necessary.

If gen_next_item does not have that behavior, you could still use:

  print "my \@list = (";
  print "\n\t$_" if defined($_ = gen_next_item);
  print ",\n\t$_" while defined $_ && defined($_ = gen_next_item);
  print "\n);\n";

Don't get me wrong -- I much prefer allowing the trailing comma.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 22 Aug 2001 19:35:48 GMT
From: abigail@foad.org (Abigail)
Subject: Re: days since 1/1/1970
Message-Id: <slrn9o82d0.6m2.abigail@alexandra.xs4all.nl>

Valentin 30IR976 (radiotito@yahoo.com) wrote on MMCMXIII September
MCMXCIII in <URL:news:3B83E612.5E0A9EA@yahoo.com>:
:} I would need to get exactly days since 1/1/1970. I need to put this

time() gives you seconds since 1/1/1970. Since 1970, days have had the
same amount of seconds. [1] Perl has a division operator.

:}                                                  I need to put this
:} amount of days on /etc/shadow file on Linux system.

Let me guess, you want to do this from a CGI program, right?


[1] No, DST is totally irrelevant. time() ignores DST too.



Abigail
-- 
perl -Mstrict='}); print "Just another Perl Hacker"; ({' -le1
#    Five flies buzzing. The
#    Shogun departs beside a
#    pool. Two cows. A fox.


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

Date: Wed, 22 Aug 2001 13:40:07 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: days since 1/1/1970
Message-Id: <3b8418a8$1@news.microsoft.com>

"Abigail" <abigail@foad.org> wrote in message
news:slrn9o82d0.6m2.abigail@alexandra.xs4all.nl...
> Valentin 30IR976 (radiotito@yahoo.com) wrote on MMCMXIII September
> MCMXCIII in <URL:news:3B83E612.5E0A9EA@yahoo.com>:
> :} I would need to get exactly days since 1/1/1970. I need to put this
>
> time() gives you seconds since 1/1/1970. Since 1970, days have had the
> same amount of seconds.

This is not totally accurate. There have been a few years where additional
seconds have been inserted to adjust our artifical time to the actual sun
time.
But I guess in the context the OPs question it will be close enough to
assume all days since 1970 have the same length.

jue




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

Date: Wed, 22 Aug 2001 16:18:03 -0400
From: Guillaume Filion <gfk@spamcop.net>
Subject: Directory listing order
Message-Id: <gfk-07749D.16180322082001@news.videotron.net>

Hi all,

I'd like to read the content of a directory in this order: files first, 
then directories. The order of the files or directory is not important 
as long as all the files are first.

Here's how I implemented this:
-----
opendir CACHEDIR, $dirpath or die "serious dainbramage: $!";
my @allfiles = readdir CACHEDIR;
closedir CACHEDIR;
      
my @directories;
my @files;
foreach my $thing (@allfiles) {
   next if ($thing =~ /^\.\.?$/ or not $thing);
   push(@directories, $thing) if (-d "$dirpath/$thing");
   push(@files, $thing) if (-f "$dirpath/$thing");
}
push(@files, @directories);
-----

It seems to me like a lot of code just to do this... Does any one of you 
knows a better/simplier way to do this?

Thanks a lot,
GFK's


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

Date: 22 Aug 2001 21:12:57 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Directory listing order
Message-Id: <slrn9o8n8l.c8j.trammell@haqq.hypersloth.net>

On Wed, 22 Aug 2001 16:18:03 -0400, Guillaume Filion wrote:
> Hi all,
> 
> I'd like to read the content of a directory in this order: files first, 
> then directories. The order of the files or directory is not important 
> as long as all the files are first.

[ ~/test/readdir ] cat -n foo.pl
     1  #!/usr/bin/perl -w
     2
     3  use strict;
     4
     5  my $dir = shift || die "usage: $0 dir";
     6  my @dirs;
     7
     8  opendir(DIR,$dir) or die "can't open '$dir': $!";
     9  @dirs = map { -d "$dir/$_" ? [dir=>$_] : [notdir=>$_] } readdir(DIR);
    10  closedir(DIR);
    11
    12  for (sort {$a->[0] cmp $b->[0]} @dirs) {print "$_->[0]: $_->[1]\n"}
    13
[ ~/test/readdir ] ls -a1F
 ./
 ../
foo.pl*
[ ~/test/readdir ] mkdir bar ; touch baz
[ ~/test/readdir ] ./foo.pl .
dir: .
dir: ..
dir: bar
notdir: foo.pl
notdir: baz
[ ~/test/readdir ]

-- 
Salad: it's what's for dinner, for what's for dinner.


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

Date: Wed, 22 Aug 2001 19:42:58 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: error handling question ;O)
Message-Id: <998509378.263815285637975.gnarinn@hotmail.com>

In article <BGLg7.140832$z11.2790152@amsnews02.chello.com>,
nick <nmudie@chello.com> wrote:

>I am using cgi scripts to call information from an oracle database.
>
>I have a couple of dropdown lists (Month and Year) which the user can choose
>from the html frontend.
>
>If he/she chooses February and 2001 then the @tablename array you see in the
>code below becomes network_m_200102.


i assume you know what you are doing, using an array for this

>This table doesn't exist so the cgi
>fails. If he/she chooses July 2001 then it works because that does exist
>(network_m_200107).
>
>Basically, I need to find out how to put in error control for when the table
>DOESN'T exist by using die/else/$error or any other means. CAN YOU HELP????
>:o)
>

i would try to put a 'or die' after the prepare statement

you can also wrap the stuff into a eval() and check $@

or probably the best solution: just ask oracle if the table exists:
   "select table_name from user_tables where table_name = '$tablename'"
or something like that.

gnari


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

Date: 22 Aug 2001 14:05:09 -0700
From: lcamargo@vesper.com.br (Nomade)
Subject: Error in a if.elsif construction
Message-Id: <39dc7e6e.0108221305.2dc9042d@posting.google.com>

Hi all,

syntax error at ./check_log.pl line 37, near "}"
syntax error at ./check_log.pl line 40, near "}"
Execution of ./check_log.pl aborted due to compilation errors.


In the following piece of code i get the above error return, line 37
is the elsif statement... :


if ( scalar @err_grep == 0 && $err_counter == 14 || $err_counter == 18
|| $err_counter == 24 || $err_counter == 25 || $err_counter == 60 )
{
print ("SAP - $err_counter on $current_log") ;
}
elsif ( scalar @err_grep == 0 && $err_counter == 59 || $err_counter ==
(47..54)
{
print ("PRODUCAO - $err_counter on $current_log") ;
}

Mayhap it happen bcoz i´m usin ( and ) inside others ( and ) ,
dunno...

Any clue/advice about ??

Thnx in adv

Nomade


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

Date: Wed, 22 Aug 2001 23:35:08 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Error in a if.elsif construction
Message-Id: <3B84258C.4050103@post.rwth-aachen.de>

Nomade wrote:

> Hi all,
> 
> syntax error at ./check_log.pl line 37, near "}"
> syntax error at ./check_log.pl line 40, near "}"
> Execution of ./check_log.pl aborted due to compilation errors.
> 
> 
> In the following piece of code i get the above error return, line 37
> is the elsif statement... :
> 
> 
> if ( scalar @err_grep == 0 && $err_counter == 14 || $err_counter == 18
> || $err_counter == 24 || $err_counter == 25 || $err_counter == 60 )
> {
> print ("SAP - $err_counter on $current_log") ;
> }
> elsif ( scalar @err_grep == 0 && $err_counter == 59 || $err_counter ==
> (47..54)
           ^^^
Something missing in the above line, isn't there?
Hint: Count the left- and right-parens.

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: 22 Aug 2001 13:06:16 -0700
From: glchy@email.com (GC)
Subject: Executing DEL and UPDT PL/SQL stored procedures from PERL
Message-Id: <be75cede.0108221206.74040dd5@posting.google.com>

Hi,

i was wondering whether it is possible (and more importantly how!) to
execute some PL/SQL stored procedures on Oracle (stprocs) from PERL.

I know using DBI, perl can execute SELECT stprocs but what about
DELETE and UPDATES? Also can those DELETE and UPDATES stprocs return a
value to PERL (say number of rows deleted or updated)?

In these codes, im actually calling a stproc found in a Package and it
simply select date from dual.

use DBI qw(:sql_types);

       my $today;

       $csr = $dbh->prepare(q{
             BEGIN
                 PACK_TEST.TEST_PROC (:today);
             END;
       });

       $csr->bind_param_inout(":today", \$today, 20);
       $csr->execute;
       print "Today is $today\n";

       $dbh->disconnect;


Is there some equivalent codes for DELETE and UPDATE?

Thanks,

GC.


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

Date: 22 Aug 2001 19:30:30 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Extracting Blocks of text
Message-Id: <slrn9o8232.6m2.abigail@alexandra.xs4all.nl>

flii (flii@zoom.co.uk) wrote on MMCMXIII September MCMXCIII in
<URL:news:e53f8197.0108220750.3fe4c0d2@posting.google.com>:
== I'm sure I'm probably duplicating a past thread, so apologies, but
== after an afternoon of searching through deja.com, I've still not quite
== been able to come up with what I'm after.
== 
== Put simply, a trying to write a short script to extract simple blocks
== of text from a ASCII file. The beginning of the text block starts with
== a particular string and is terminated with another string or character
== (I'm actually extracting blocks of SQL from PL/SQL scripts).
== Therefore, the blocks of text are of a variable size, and may be quite
== large.


You might want to look into the .. operator. One of it's purposes is
to do just that.



Abigail
-- 
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;


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

Date: Wed, 22 Aug 2001 18:58:37 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Help w/grep
Message-Id: <998506717.481430604122579.gnarinn@hotmail.com>

In article <f02c4576.0108220048.2d019cac@posting.google.com>,
Ian Boreham <ianb@ot.com.au> wrote:
>gnari <gnarinn@hotmail.com> wrote in message news:<998418421.259762815665454.gnarinn@hotmail.com>...
>> In article <3B7AA3DC.4D001409@cca-int.com>, jlm  <jlm@cca-int.com> wrote:
>> >I wrote a search engine in perl/cgi for our web site that searches for
>> >files containing user supplied text string.
>> >@farr = `find $dir -type f -exec grep -il $text {} \\;`;
>> 
>> 
>> i usually just pipe the output to another grep process:
>> 
>>   grep foo pod/*.pod | grep bar
>
>This will only find files with those two strings on the same line.

sorry. i misinterpreted the OP's question

gnari


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

Date: Wed, 22 Aug 2001 20:31:21 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: How do I sort a 2D-array by three different columns with perl
Message-Id: <998512281.146006953436881.gnarinn@hotmail.com>

In article <3b828e84$1@news.microsoft.com>,
Jürgen Exner <jurgenex@hotmail.com> wrote:
>"ED" <gineric2@mindspring.com> wrote in message
>news:88105013.0108202127.768e0fb4@posting.google.com...
>> I need a way to sort a 2D-array by one column, then by a second, and
>> finally by a third. [...]
>>
>> I know how to sort by a single column using:
>> @sorted_result = sort { $a->[5] cmp $b->[5] } @result;
>> where 5 is the column to sort the rows by.  However, how do I expand
>> on this to then sort by a second and third column without comprimising
>> the original sort?
>
>Two possibilities:
>- create a more complex compare function which takes all three columns into
>account
>- or simply sort by the third column first, then the same array by the
>second, and again by the first. Since Perl 5.6 "sort" is stable, i.e. if two
>elements have the same ranking it will preserve there order

is this property documented, and likely to be preserved in future
versions of perl?

gnari


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

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


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