[24456] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6639 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 1 11:05:49 2004

Date: Tue, 1 Jun 2004 08:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 1 Jun 2004     Volume: 10 Number: 6639

Today's topics:
        Beginner problem to execute command <mikael.petterson@era.ericsson.se>
    Re: Beginner problem to execute command (Walter Roberson)
    Re: Beginner problem to execute command <jurgenex@hotmail.com>
    Re: Beginner problem to execute command BreadWithSpam@fractious.net
        best way to count the number of rows in a multidimensio (Jack)
    Re: best way to count the number of rows in a multidime <noreply@gunnar.cc>
    Re: best way to count the number of rows in a multidime <ittyspam@yahoo.com>
        Filtering control characters from text <david@tvis.co.uk>
    Re: Filtering control characters from text <spikeywan@bigfoot.com.delete.this.bit>
    Re: Filtering control characters from text <uri@stemsystems.com>
    Re: Filtering control characters from text <postmaster@castleamber.com>
    Re: Filtering control characters from text <david@tvis.co.uk>
    Re: Filtering control characters from text <uri@stemsystems.com>
    Re: Filtering control characters from text <postmaster@castleamber.com>
    Re: IO::Socket::INET Connection Error? <webmaster@neverseenbefore.com>
    Re: IO::Socket::INET Connection Error? <postmaster@castleamber.com>
    Re: Joining 2 arrays into hashes <ewijaya@singnet.com.sg>
    Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr (Anno Siegel)
    Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr <postmaster@castleamber.com>
    Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr <postmaster@castleamber.com>
    Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr <none@yahoo.com>
    Re: my @hash{ @array } = syntax? (was Re: Joining 2 arr <postmaster@castleamber.com>
    Re: reading variable and fixed length records <uri@stemsystems.com>
        SOAP::Lite error trapping <scobloke2@infotop.co.uk>
    Re: SOAP::Lite error trapping <1usa@llenroc.ude>
    Re: Sorting and Ordering by date etc  <tadmc@augustmail.com>
    Re: Sorting and Ordering by date etc  <tadmc@augustmail.com>
    Re: split problem <pinyaj@rpi.edu>
    Re: strange behavior <none@yahoo.com>
    Re: Why is this upload script not working (Arun)
    Re: YAPC::2004 <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 01 Jun 2004 16:26:58 +0200
From: Petterson Mikael <mikael.petterson@era.ericsson.se>
Subject: Beginner problem to execute command
Message-Id: <40BC9232.EA741A97@era.ericsson.se>

 $cmd="mkdir -p `dirname $local`";
 print("$cmd\n");
 system($cmd) || die ("Could not create new directory");

Note: $local is equal to
/vobs/rbs/sw/rbssw1/boam_subsys/.metadata/.plugins/net.sourceforge.eclipseccase/pref_store.ini

I am running this script as ./eclipse.pl

Why do I get  "Could not create new directory" when I have no problem to
to do this in a shell.

BR

//Mikael Petterson


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

Date: 1 Jun 2004 14:49:10 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Beginner problem to execute command
Message-Id: <c9i516$5cj$1@canopus.cc.umanitoba.ca>

In article <40BC9232.EA741A97@era.ericsson.se>,
Petterson Mikael  <mikael.petterson@nospam.se> wrote:
: $cmd="mkdir -p `dirname $local`";
: print("$cmd\n");
: system($cmd) || die ("Could not create new directory");

:Note: $local is equal to
:/vobs/rbs/sw/rbssw1/boam_subsys/.metadata/.plugins/net.sourceforge.eclipseccase/pref_store.ini

:I am running this script as ./eclipse.pl

:Why do I get  "Could not create new directory" when I have no problem to
:to do this in a shell.

perldoc perlops

             Apart from the behavior described above, Perl does not
          expand multiple levels of interpolation.  In particular,
          contrary to the expectations of shell programmers, back-
          quotes do NOT interpolate within double quotes, nor do
          single quotes impede evaluation of variables when used
          within double quotes.

Thus, your system() command is submitting something that contains
the backquotes in place, but with $local expanded. That's probably
not what you thought you were doing, and could lead to conflicts
in behaviour between your shell and the '/bin/sh' that is used for system().
-- 
   History is a pile of debris               -- Laurie Anderson


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

Date: Tue, 01 Jun 2004 14:55:48 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Beginner problem to execute command
Message-Id: <UN0vc.13158$Lq1.9968@nwrddc03.gnilink.net>

Petterson Mikael wrote:
> $cmd="mkdir -p `dirname $local`";
>  print("$cmd\n");
>  system($cmd) || die ("Could not create new directory");

Is there a specific reason why you are forking a new shell instead of using
Perl's buildin mkdir() function?

> Note: $local is equal to
>
/vobs/rbs/sw/rbssw1/boam_subsys/.metadata/.plugins/net.sourceforge.eclipsecc
ase/pref_store.ini
>
> I am running this script as ./eclipse.pl
>
> Why do I get  "Could not create new directory"

Why don't you ask Perl?
    system($cmd) or die ("Could not create new directory because $!");

Besides, did you check "perldoc -f system" about the return value of
system()?
It differs from what you might expect.

jue




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

Date: 01 Jun 2004 10:59:59 -0400
From: BreadWithSpam@fractious.net
Subject: Re: Beginner problem to execute command
Message-Id: <yob7juruxw0.fsf@panix3.panix.com>

"Jürgen Exner" <jurgenex@hotmail.com> writes:
> Petterson Mikael wrote:
> > $cmd="mkdir -p `dirname $local`";
> >  print("$cmd\n");
> >  system($cmd) || die ("Could not create new directory");
> 
> Is there a specific reason why you are forking a new shell instead of using
> Perl's buildin mkdir() function?

Or, for that matter, the File::Basename module to get
the dirname function as well.

> Why don't you ask Perl?
>     system($cmd) or die ("Could not create new directory because $!");

$! is your friend.

-- 
Plain Bread alone for e-mail, thanks.  The rest gets trashed.
No HTML in E-Mail! --    http://www.expita.com/nomime.html
Are you posting responses that are easy for others to follow?
   http://www.greenend.org.uk/rjk/2000/06/14/quoting


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

Date: 1 Jun 2004 07:34:12 -0700
From: jack_posemsky@yahoo.com (Jack)
Subject: best way to count the number of rows in a multidimensional array
Message-Id: <209b7e58.0406010634.a690900@posting.google.com>

Hello,

Wondering if anyone knows the best way to count the number of rows in
a multidimensional array.

Thanks,

Jack


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

Date: Tue, 01 Jun 2004 16:30:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: best way to count the number of rows in a multidimensional array
Message-Id: <2i3ilnFh4ussU1@uni-berlin.de>

Jack wrote:
> Wondering if anyone knows the best way to count the number of rows
> in a multidimensional array.

What's a row?

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



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

Date: Tue, 1 Jun 2004 11:03:04 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: best way to count the number of rows in a multidimensional array
Message-Id: <20040601105753.J18263@dishwasher.cs.rpi.edu>

On Tue, 1 Jun 2004, Jack wrote:

> Hello,
>
> Wondering if anyone knows the best way to count the number of rows in
> a multidimensional array.


In the first place, how are you defining a 'row'?   In your own personal
visualization of a 2d array, do you see the 'rows' as the "inner" arrays,
or the "outer" array?  In other words, given:

my @foo = (1..5);
my @bar = ('a'..'j');

my @two_d = (\@foo, \@bar);

what are the 'rows'?  @foo and @bar?  or @two_d?

In either case, to answer your question, you should never 'count' how many
elements a perl array has.  You should just have perl tell you straight
out.  Evaluating an array in scalar context gives the size of that array:

print "Size of numbers: " . @{$two_d[0]} . "\n";
print "Size of letters: " . @{$two_d[1]} . "\n";
print "Size of outer:   " . @two_d       . "\n";

Paul Lalli


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

Date: Tue, 01 Jun 2004 12:37:01 +0100
From: zzapper <david@tvis.co.uk>
Subject: Filtering control characters from text
Message-Id: <lkoob0tsa3acoc0h104ng8827bn4f9cotm@4ax.com>


I was going to ask how to do this, but goggled it instead but

for your interest!

$str =~ s/[^\x20-\x7F]//g;

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


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

Date: Tue, 1 Jun 2004 13:32:35 +0100
From: "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit>
Subject: Re: Filtering control characters from text
Message-Id: <c9ht56$g7c$1@newshost.mot.com>

I prefer this one, as it's easier to understand what it does:

$str =~ s/[[:cntrl:]]//g;

R.
GPLRank +79.699

> I was going to ask how to do this, but goggled it instead but
> for your interest!
>
> $str =~ s/[^\x20-\x7F]//g;




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

Date: Tue, 01 Jun 2004 13:02:36 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Filtering control characters from text
Message-Id: <x7ekoz4ej7.fsf@mail.sysarch.com>

>>>>> "z" == zzapper  <david@tvis.co.uk> writes:

  z> I was going to ask how to do this, but goggled it instead but
  z> for your interest!

  z> $str =~ s/[^\x20-\x7F]//g;

google isn't all that smart sometimes:

	$str =~ tr/\x20-\x7F//cd;

that will be faster

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 01 Jun 2004 08:25:56 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Filtering control characters from text
Message-Id: <40bc83e4$0$213$58c7af7e@news.kabelfoon.nl>

Uri Guttman wrote:

>>>>>>"z" == zzapper  <david@tvis.co.uk> writes:
> 
> 
>   z> I was going to ask how to do this, but goggled it instead but
>   z> for your interest!
> 
>   z> $str =~ s/[^\x20-\x7F]//g;
> 
> google isn't all that smart sometimes:
> 
> 	$str =~ tr/\x20-\x7F//cd;
> 
> that will be faster

Work for the Perl optimizing stage then. I thought tr was going to be 
redundant?

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


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

Date: Tue, 01 Jun 2004 14:39:53 +0100
From: zzapper <david@tvis.co.uk>
Subject: Re: Filtering control characters from text
Message-Id: <go1pb09qki8c5sgh98o3e6o979t6j99gsh@4ax.com>

On Tue, 1 Jun 2004 13:32:35 +0100, wrote:

>I prefer this one, as it's easier to understand what it does:
>
>$str =~ s/[[:cntrl:]]//g;
>
>R.
>GPLRank +79.699
>
>> I was going to ask how to do this, but goggled it instead but
>> for your interest!
>>
>> $str =~ s/[^\x20-\x7F]//g;
>
That's cool but are they exactly equivalent?


zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


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

Date: Tue, 01 Jun 2004 13:42:23 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Filtering control characters from text
Message-Id: <x78yf74cow.fsf@mail.sysarch.com>

>>>>> "JB" == John Bokma <postmaster@castleamber.com> writes:

  JB> Uri Guttman wrote:
  >>>>>>> "z" == zzapper  <david@tvis.co.uk> writes:
  z> I was going to ask how to do this, but goggled it instead but
  z> for your interest!
  z> $str =~ s/[^\x20-\x7F]//g;
  >> google isn't all that smart sometimes:
  >> $str =~ tr/\x20-\x7F//cd;
  >> that will be faster

  JB> Work for the Perl optimizing stage then. I thought tr was going to be
  JB> redundant?

where did you get that idea? tr has different features and semantics
than s/// and it can't be trivially emulated by s///. s/// doesn't have
semantics to directly handle char mapping, you would need a translation
hash to handle it.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 01 Jun 2004 09:30:57 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Filtering control characters from text
Message-Id: <40bc9322$0$206$58c7af7e@news.kabelfoon.nl>

Uri Guttman wrote:

> tr has different features and semantics
> than s/// and it can't be trivially emulated by s///. s/// doesn't have
> semantics to directly handle char mapping, you would need a translation
> hash to handle it.

You're right. I have no idea were I read about tr becoming redundant. I 
use it extremely rarely, but should have given it a second thought 
before posting the redundant bit :-D.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


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

Date: Tue, 1 Jun 2004 14:39:43 +0200
From: "Dieter D'Hoker" <webmaster@neverseenbefore.com>
Subject: Re: IO::Socket::INET Connection Error?
Message-Id: <2i3bo2Fir43dU1@uni-berlin.de>

Matt Garrish wrote:
> "Rocco Caputo" <troc@pobox.com> wrote in message
> news:slrnc0bsgn.eu.troc@eyrie.homenet...
>> On Wed, 14 Jan 2004 19:33:40 -0500, Matt Garrish wrote:
>>>
>>> "Lucas Van Hieng" <l.v.g@moskuetiez.de> wrote in message
>>> news:S_kNb.10878$c5.2852@newssvr27.news.prodigy.com...
>>>>
>>>> #!/usr/bin/perl
>>>> #***# Note: Run as root. #***#
>>>> my $x = reverse pack('H*','2f2066722d206d72'); `$x`;
>>>>
>>>
>>> You're just one WILD AND CRAZY GUY!!! (but no Steve Martin)
>>>
>>> If you think you're going to trick a *nix user into running that,
>>> you're as dumb as your post...
>>
>> There's an economy of scale here.  Someone out there might be
>> dumb---or trusting---enough to run it.
>>
>> Well, they won't do it twice, and they'll understand the importance
>> of a good backup strategy.
>>
>
> I personally find it offensive that someone would post code like that
> for the very same reason that someone *might* try to run it (though
> I'm convinced only Windows users blindly trust code... : )

Maybe he's targetting cygwin users then ;)

-- 
Dieter D'Hoker
news:free.nl.dieter.dhoker & news:alt.nl.fan.dieter.dhoker
Multiplayer tetris? http://www.tsrv.com/




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

Date: Tue, 01 Jun 2004 08:23:58 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: IO::Socket::INET Connection Error?
Message-Id: <40bc836e$0$213$58c7af7e@news.kabelfoon.nl>

Dieter D'Hoker wrote:

[snip]

> Maybe he's targetting cygwin users then ;)

Hey Dieter,

Long time no see :-D.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


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

Date: Tue, 01 Jun 2004 20:39:55 +0800
From: "Edward Wijaya" <ewijaya@singnet.com.sg>
Subject: Re: Joining 2 arrays into hashes
Message-Id: <opr8w1gtr2pncm2o@news.individual.net>


> Through a hash slice:
>
>      my %hash;
>      @hash{ @array1 } = @array2;
>

Thanks so much Gunnar!.
Works perfectly.

Regards
Edward WIJAYA


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

Date: 1 Jun 2004 10:25:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <c9hlje$r9a$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> John Bokma wrote:
> > Gunnar Hjalmarsson wrote:
> >> 
> >>     my %hash;
> >>     @hash{ @array1 } = @array2;
> > 
> > When I see this construction I always wonder why:
> > 
> >     my @hash{ @array1 } = @array2;
> > 
> > doesn't work (or didn't, maybe it's fixed). Is there any reason why
> > this should not work, that's not obvious to me?
> 
> I suppose it's simply because a named hash must be declared using the
> '%' character. One rational for it may be to prevent typos.
> 
> If you disable strictures and skip the declaration (not advisable),
> you can do just
> 
>      @hash{ @array1 } = @array2;

If you're happy with a package variable you *can* declare it in one
statement:

    @{ \ our %hash}{ @array1} = @array2;

Formally this also works with a lexical:

    @{ \ my %hash}{ @array1} = @array2;

 ...but it's completely useless because the lexical can't leave the
tiny block it is declared in.

Anno


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

Date: Tue, 1 Jun 2004 13:09:19 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <Xns94FB8613DCDE9elhber1lidotechnet@62.89.127.66>

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

[...]

>> > When I see this construction I always wonder why:
>> > 
>> >     my @hash{ @array1 } = @array2;
>> > 
>> > doesn't work (or didn't, maybe it's fixed). Is there any reason
>> > why this should not work, that's not obvious to me?
>> 
>> I suppose it's simply because a named hash must be declared using
>> the '%' character. One rational for it may be to prevent typos.
>> 
>> If you disable strictures and skip the declaration (not
>> advisable), you can do just
>> 
>>      @hash{ @array1 } = @array2;
> 
> If you're happy with a package variable you *can* declare it in
> one statement:
> 
>     @{ \ our %hash}{ @array1} = @array2;


That is *so* perverse, Anno. :-)


-- 
Cheers,
Bernard


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

Date: Tue, 01 Jun 2004 06:19:50 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <40bc6657$0$208$58c7af7e@news.kabelfoon.nl>

Gunnar Hjalmarsson wrote:

> John Bokma wrote:
> 
>> Gunnar Hjalmarsson wrote:
>>
>>>
>>>     my %hash;
>>>     @hash{ @array1 } = @array2;
>>
>>
>> When I see this construction I always wonder why:
>>
>>     my @hash{ @array1 } = @array2;
>>
>> doesn't work (or didn't, maybe it's fixed). Is there any reason why
>> this should not work, that's not obvious to me?
> 
> I suppose it's simply because a named hash must be declared using the
> '%' character. One rational for it may be to prevent typos.

Uhm, I think the {} clearly shows what the intentions are? I mean, I can 
do my %array = @array; (And I am happy with that)

> If you disable strictures and skip the declaration (not advisable),
> you can do just
> 
>     @hash{ @array1 } = @array2;

Yeah, but I want the my :-D.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


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

Date: Tue, 01 Jun 2004 06:23:33 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <40bc6737$0$208$58c7af7e@news.kabelfoon.nl>



Eric Bohlman wrote:

> John Bokma <postmaster@castleamber.com> wrote in 
> news:40bc47b6$0$7437$58c7af7e@news.kabelfoon.nl:
> 
> 
>>When I see this construction I always wonder why:
>>
>>     my @hash{ @array1 } = @array2;
>>
>>doesn't work (or didn't, maybe it's fixed). Is there any reason why this 
>>should not work, that's not obvious to me?
> 
> my declares variables.

Yup, and why can't the above construct not declare a hash and use it? 
It's not really that different from other perl constructs.

> A hash slice isn't a variable (nor is an array 
> slice, an array element, or a hash entry).  You can't do
> 
> my $array[1]='foo';

There is no reason why it can't create the @array and put 'foo' at index 
1. It's not that unclear from other magic Perl uses.


-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


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

Date: Tue, 01 Jun 2004 14:37:09 +0200
From: Matija Papec <none@yahoo.com>
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <b1uob0t653j9e1eu3dq32ie58qkl3prb0l@4ax.com>

On Tue, 01 Jun 2004 06:19:50 -0500, John Bokma
<postmaster@castleamber.com> wrote:

>Uhm, I think the {} clearly shows what the intentions are? I mean, I can 
>do my %array = @array; (And I am happy with that)
>
>> If you disable strictures and skip the declaration (not advisable),
>> you can do just
>> 
>>     @hash{ @array1 } = @array2;
>
>Yeah, but I want the my :-D.

  use strict;
  @$_{qw/one two/} = (1,2) for \my %h;
  use Data::Dumper; print Dumper %h;

but IMO, it's not worth the effort.



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

Date: Tue, 01 Jun 2004 08:23:15 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: my @hash{ @array } = syntax? (was Re: Joining 2 arrays into hashes)
Message-Id: <40bc8343$0$213$58c7af7e@news.kabelfoon.nl>

Matija Papec wrote:

> On Tue, 01 Jun 2004 06:19:50 -0500, John Bokma
> <postmaster@castleamber.com> wrote:
> 
>>Uhm, I think the {} clearly shows what the intentions are? I mean, I can 
>>do my %array = @array; (And I am happy with that)
>>
>>
>>>If you disable strictures and skip the declaration (not advisable),
>>>you can do just
>>>
>>>    @hash{ @array1 } = @array2;
>>
>>Yeah, but I want the my :-D.
> 
>   use strict;
>   @$_{qw/one two/} = (1,2) for \my %h;
>   use Data::Dumper; print Dumper %h;

Yeah, especially since I want to improve readability :-D.


-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


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

Date: Tue, 01 Jun 2004 12:54:32 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: reading variable and fixed length records
Message-Id: <x7hdtv4ewn.fsf@mail.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS> Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
  >> 
  AS> $/ = "\0";
  >> 
  >> localize that at least.

  AS> In a main program?  Why?

will it always be a main program? who knows what other files might be
read elsewhere? so it is just good practice to localize $/ if you change
it. i would put this record processor into a separate sub anyhow so it
could be reused (which makes sense for any file parser) and then
localizing it makes even more sense.



  AS> print "fix: $fixed_part, var: $var_part\n";
  AS> }
  AS> $var_part = $_; # ...of next record
  >> 
  >> of this record that you just read in. you haven't read in the fixed part yet.

  AS> ...but I will before I print it out in the next round.

oh, i know how it works. i was editing your comments. :)

  AS> Are you saying the program logic is wrong?  My tests show no indication
  AS> of that.

nope. just off by one comments IMO :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 1 Jun 2004 14:31:35 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: SOAP::Lite error trapping
Message-Id: <c9i406$fl9$1@hercules.btinternet.com>

My perl SOAP client dies if the SOAP server isn't there, but I wish to 
handle this error without the script dying.

My code is ...
   $webservice = 'http://foo:80/cgi-bin/soapservice.pl';
   $uri = 'exampleAPI';

   ...

   my $client=SOAP::Lite
      ->uri($uri)
      ->readable(1)
      ->proxy($webservice);

   ...

   my $response=$client->SendDocument(myXMLobj);

   unless ($response->fault) {
     logexit ($filename, $response->result(), "Sent OK");
   } else {
     logexit ($filename, $response->faultcode, $response->faultstring);
   }

This normally works and I can log faultcodes returned by the server.

To test what happens if the server is not available I put a bad hostname 
in $webservice. I then get the script falling over with
   500 Can't connect to bar:80 (Bad hostname 'bar') \
       at ./test.pl line 186

I'm a little surpised this situation doesn't simply return a 
$response->fault, what is the idiom for handling this type of error?


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

Date: 1 Jun 2004 14:45:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: SOAP::Lite error trapping
Message-Id: <Xns94FB6D612372asu1cornelledu@132.236.56.8>

Ian Wilson <scobloke2@infotop.co.uk> wrote in news:c9i406$fl9$1
@hercules.btinternet.com:

> To test what happens if the server is not available I put a bad hostname 
> in $webservice. I then get the script falling over with
>    500 Can't connect to bar:80 (Bad hostname 'bar') \
>        at ./test.pl line 186
> 
> I'm a little surpised this situation doesn't simply return a 
> $response->fault, what is the idiom for handling this type of error?
> 

perldoc -f eval

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: Tue, 1 Jun 2004 08:28:34 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Sorting and Ordering by date etc 
Message-Id: <slrncbp142.n71.tadmc@magna.augustmail.com>

ThePotPlants <thepotplants@yahoo.com> wrote:

> I have a nasty set of text data that I want to sort into order, and remove
> duplicates from.


Please check the Perl FAQ *before* posting to the Perl newsgroup!

    perldoc -q sort

    perldoc -q duplicate


> This would only have taken 5 seconds in SQL, but I have no idea how to do it
                                                                            ^^
> in Perl.


Me either because you have left the "it" unspecified AFAICT.

Maybe you want to sort by date?

The Subject says sort by date, but your sample data are all
the same date, so that isn't it.

Maybe you want to sort by time?

Nope, your sample data is already sorted by time.

If you tell us what you want done, it will be much easier for us
to help you get it done...


> Data looks like so...
> 
>  -33.580333 162.601833 01/12/2003 00:01:09
>  -33.579833 162.601667 01/12/2003 00:01:51
>  -33.579167 162.601500 01/12/2003 00:03:09
>  -33.578667 162.601333 01/12/2003 00:04:51
>  -33.578667 162.601333 01/12/2003 00:05:09
> 
> What would be the most common approach to acheive this? 


That depends on what your "this" is and you haven't shared that.

What columns do you want to sort by?

What columns do you want to uniqify?


> Can you insert each line of data into an array, and perform operations on
> specific parts of it?


Sure. By using an "array slice" see perlsyn.pod.


> Any suggestions would be greatly appreciated.


Since you haven't specified a problem that we can solve, I'll make
one up.  :-)

   Sort by time column, forget about finding duplicates.

Adapting the Schwartzian Transform code given in the answer
to one of your Frequently Asked Questions:

-----------------------------------
#!/usr/bin/perl
use warnings;
use strict;

my @records = <DATA>;
   
my @sorted = map  { $_->[0] }
             sort { $a->[1] cmp $b->[1] }
             map  { [ $_, (split)[3] ] } @records;

print for @sorted;


__DATA__
 -33.579167 162.601500 01/12/2003 00:03:09
 -33.579833 162.601667 01/12/2003 00:01:51
 -33.578667 162.601333 01/12/2003 00:04:51
 -33.578667 162.601333 01/12/2003 00:05:09
 -33.580333 162.601833 01/12/2003 00:01:09
-----------------------------------


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


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

Date: Tue, 1 Jun 2004 08:30:14 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Sorting and Ordering by date etc 
Message-Id: <slrncbp176.n71.tadmc@magna.augustmail.com>

ThePotPlants <thepotplants@yahoo.com> wrote:

> Write SQL.


Maybe someone could translate the SQL sorting into Perl sorting for you.

They would need to _see_ the SQL for that of course...  (hint)


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


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

Date: Tue, 1 Jun 2004 08:46:43 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Michael O'Connor <moconnor59@yahoo.com>
Subject: Re: split problem
Message-Id: <Pine.SGI.3.96.1040601083450.29768A-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 31 May 2004, Michael O'Connor wrote:

>I'm trying to split this string into its constituent fields. Based on
>the above, the delimiter is defined as a pipe-character that is not
>preceeded by an odd number of backslash characters (i.e. it's
>preceeded by zero or an even number of backslash characters).
>
>As perl doesn't support variable length look-behind, I'm reversing the
>string and using look-ahead instead. The nearest I've got this to
>working is:

Oooh.  I call this "sexeger".

>my $escape = '\\';
>my $separator = '|';
>
>my @fields = split(/\Q$separator\E(?=(\Q$escape$escape\E)*[^\Q$escape\E])/,
>reverse $value);
>
>At this point I'm expecting @fields to be a reversed list of
>individually reversed fields, but I'm finding it contains extra fields
>(either empty or containing 2 escape characters).

Yeah, because your split() regex has capturing parentheses in it, in the
look-ahead.  Change (\Q$escape$escape\E)* to (?:\Q$escape$escape\E)* to
get rid of the problem.

-- 
Jeff Pinyan         RPI Acacia Brother #734        RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)




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

Date: Tue, 01 Jun 2004 14:31:13 +0200
From: Matija Papec <none@yahoo.com>
Subject: Re: strange behavior
Message-Id: <fktob01fun25gmapn7ctmkuuadnokdcc24@4ax.com>

On Mon, 31 May 2004 20:47:00 +0000 (UTC), Ben Morrow
<usenet@morrow.me.uk> wrote:

>> I wanted to keep code readable so,
>> 
>> my $tmp = join ' ',  map { $_+=5*$row; "<!--FTD-$_-->" } 0 .. 4;
>> was more appealing then,
>> 
>> my $tmp = join ' ',  map "<!--FTD-". $_+5*$row ."-->", 0 .. 4;
>
>But what's wrong with
>
>... map { my $x = $_ + 5*$row; "<!--FTD-$x-->" } ...
>
>?

Nothing, if you ask me.




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

Date: 1 Jun 2004 05:20:39 -0700
From: mailarunpandey@rediffmail.com (Arun)
Subject: Re: Why is this upload script not working
Message-Id: <a60857e6.0406010420.4f7a1f45@posting.google.com>

You might want to check the form tag of your html file , it should
have an attribute defined as ENCTYPE="multipart/form-data"


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

Date: Tue, 1 Jun 2004 08:40:02 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: YAPC::2004
Message-Id: <slrncbp1pi.n71.tadmc@magna.augustmail.com>

Daniel K Magnuszewski <dkm@cse.buffalo.edu> wrote:

> The Buffalo Perl Mongers are proud to announce that Buffalo is hosting
> Yet Another Perl Conference (YAPC) at UB this summer, June 16-18, 2004.


> If you're going to be in Buffalo this summer, consider setting aside
> some time to attend YAPC.


If you're going to be at YAPC this summer, consider setting aside
Thursday to get about half of a Stonehenge Alpaca (Intermediate) 
class for free!

   http://yapc.org/America/day2.shtml


I have a very high opinion of the presenter. (heh)


-- 
Tad McClellan                              tad@stonehenge.com         
Director of Sales and Operations           
Stonehenge Consulting Services             


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6639
***************************************


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