[29167] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 411 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 6 21:09:48 2007

Date: Sun, 6 May 2007 18:09:06 -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           Sun, 6 May 2007     Volume: 11 Number: 411

Today's topics:
    Re: Home-built Twirling Bar Between Multiple System Cal <m@rtij.nl.invlalid>
    Re: how to join array into array <joe@inwap.com>
    Re: how to join array into array <joe@inwap.com>
    Re: how to join array into array <someone@example.com>
    Re: how to join array into array <someone@example.com>
    Re: how to join array into array <tadmc@augustmail.com>
    Re: need a quick script <cdalten@gmail.com>
    Re: need a quick script <tadmc@augustmail.com>
    Re: need a quick script <noreply@gunnar.cc>
    Re: need a quick script <spamtrap@dot-app.org>
    Re: need a quick script <spamtrap@dot-app.org>
    Re: need a quick script <spamtrap@dot-app.org>
    Re: need a quick script <noreply@gunnar.cc>
    Re: need a quick script <noreply@gunnar.cc>
    Re: need a quick script <cdalten@gmail.com>
    Re: Populating an array from a mysql select <jgibson@mail.arc.nasa.gov>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 6 May 2007 22:17:18 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Home-built Twirling Bar Between Multiple System Calls
Message-Id: <pan.2007.05.06.20.17.21@rtij.nl.invlalid>

On Sun, 06 May 2007 08:20:03 -0700, foolishbrat wrote:

> Dear all,
> AFAIK, progress/twirling bar can only be applied under loops. For
> example we can use Term::ProgressBar or Smart::Comments. But is there
> away to do it for system call like this:
> 
> __BEGIN__
> #!/usr/bin/perl
> system("code1.out param1 > output.txt"); system("code2.out param2
> output.txt > output_final.txt"); __END__
> 
> How can I show progress/twirling Bar between first (code1) system call
> and the second (code2) system call? Especially we don't know how long
> each system call will take.
> 
> Preferrably not using external CPAN module (except pre-installed
> module).

Easy. Fork to do the system call. In the parent show the progress bar and 
check with wait_pid if the  child is ready.

May or may not work on Windows, though, no idea really.

HTH,
M4


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

Date: Sun, 06 May 2007 11:54:41 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: how to join array into array
Message-Id: <aoadnccm-OvvuaPbnZ2dneKdnZydnZ2d@comcast.com>

Tradeorganizer wrote:

> ARRAY(0x1c653b0)ARRAY(0x1c653ec)ARRAY(0x1c6544c)ARRAY(0x1c65458)ARRAY(0x1c654c4)
> what does it mean and how to get value printed for output file.

As you found,
   print @newxy;
or
   print "$_\n" for @newxy;
does not work with arrays of arrays.

(You do know you're working with an AoA, don't you?)

You need to access each sub-array individually.

   for my $array_ref (@newxy) {
     my @sub_array = @$array_ref;
     print '(', (join ',', @sub_array), ")\n";
   }

or

   print '(',join(','=>@$_),")\n" for @newxy;


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

Date: Sun, 06 May 2007 12:46:09 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: how to join array into array
Message-Id: <5pidnbXfm8gbraPbnZ2dnUVZ_tmknZ2d@comcast.com>

Tradeorganizer wrote:
> i dont know where i am wrong i am getting ouput value as below
> ARRAY(0x1c653b0)ARRAY(0x1c653ec)ARRAY(0x1c6544c)ARRAY(0x1c65458)ARRAY(0x1c654c4)
> what does it mean

Read "perldoc perlreftut" (http://perldoc.perl.org/perlreftut.html).
Look for this section:

     o   If you try to use a reference like a string, you get
          strings like

                  ARRAY(0x80f5dec)   or    HASH(0x826afc0)

          If you ever see a string that looks like this, you'll
          know you printed out a reference by mistake.


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

Date: Sun, 06 May 2007 19:49:17 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: how to join array into array
Message-Id: <1jq%h.22145$KN6.9159@edtnps89>

Tradeorganizer wrote:
> 
> On May 6, 9:49 am, Tad McClellan <t...@augustmail.com> wrote:
>> 
>> my @newxy;
>> for ( my $xi = my $yi = 0; defined $y[$yi]; $xi++, $yi++ ) {
>>     push @newxy, [ @{ $x[$xi] }, @{ $y[$yi] } ];
>>     $xi = -1 if $xi == $#x;  # roll back to zero
>> 
>> }
>>
>> print Dumper \@newxy;
> 
> Thanks for your reply , it worked , but the output i am getting is
> below :
> 
> 
> C:\perlprog>testlooprt.pl
> 
> $VAR1 = [
>           [
>             1,
>             2,
>             3,
>             4,
>             2,
>             2,
>             3,
>             4
>           ],

[ snip ]

>           [
>             1,
>             2,
>             3,
>             4,
>             1,
>             1,
>             1,
>             1
>           ]
>         ];
> 
> where as i need like
> $VAR1 = [  [  1, 2, 3, 4, 2, 2, 3, 4 ],
> how can i do that.

Change Data::Dumper's formating options.

perldoc Data::Dumper



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Sun, 06 May 2007 19:51:54 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: how to join array into array
Message-Id: <ulq%h.22147$KN6.18043@edtnps89>

Tradeorganizer wrote:
> 
> On May 6, 8:19 am, "John W. Krahn" <some...@example.com> wrote:
>> 
>> my @newxy;
>> for my $index_y ( 0 .. $#y ) {
>>     push @newxy, [ @{ $x[ $index_y % @x ] }, @{ $y[ $index_y ] } ];
>>     }
> 
> Thanks for help , the array seems to be running fine but i dont know
> where i am wrong i am getting ouput value as
> below
> ARRAY(0x1c653b0)ARRAY(0x1c653ec)ARRAY(0x1c6544c)ARRAY(0x1c65458)ARRAY(0x1c654c4)
> what does it mean and how to get value printed for output file. kindly
> help

for my $array ( @newxy ) {
    print "@$array\n";
    }



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Sun, 6 May 2007 15:58:54 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: how to join array into array
Message-Id: <slrnf3sgce.4bb.tadmc@tadmc30.august.net>

Tradeorganizer <tradeorganizer@gmail.com> wrote:
> On May 6, 9:49 am, Tad McClellan <t...@augustmail.com> wrote:

>> Have you seen the Posting Guidelines that are posted here frequently?
>>
>> --
>>     Tad McClellan                          SGML consulting
>>     t...@augustmail.com                   Perl programming
>>     Fort Worth, Texas


It is bad manners to quote .sigs.

It is bad manners to quote an entire post when it is not needed
for context.

Have you seen the Posting Guidelines that are posted here frequently?


> Thanks for your reply , it worked , but the output i am getting is
> below :
>
>
> C:\perlprog>testlooprt.pl
>
> $VAR1 = [
>           [
>             1,
>             2,
>             3,
>             4,
>             2,
>             2,
>             3,
>             4
>           ],


> where as i need like
> $VAR1 = [  [  1, 2, 3, 4, 2, 2, 3, 4 ],
> how can i do that.


By modifying the program you've been given.

What modifications have you tried?


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


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

Date: 6 May 2007 13:22:16 -0700
From: grocery_stocker <cdalten@gmail.com>
Subject: Re: need a quick script
Message-Id: <1178482936.460058.166530@o5g2000hsb.googlegroups.com>

On May 6, 9:36 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> grocery_stocker wrote:
> > I just tried the doing it now. I took me exactly 17 minutes. The thing
> > that slowed me up was if I had the input of say
>
> > Chad Altenburg
>
> > I needed to figure out how to store the name the characters 'C' 'h'
> > 'a' 'd' in one array and 'Chad' 'Altenburg' in another array.  All
> > this was due to the fact that I have a poor grasp over regex.
>
> ???
>
>         sub nameconvert {
>                 my ($first, $last) = split ' ', shift;
>                 substr($first, 0, 1) . $last
>         }
>
>         print nameconvert('Chad Altenburg'), "\n";
>
> --

Here is perl code I wrote this morning

#!/usr/bin/perl -w

my $line=<stdin>;

$line =~ s/^\s+//;
@full_name = split(/\W/, $line);

@first_name = split(//,$line);

print "$first_name[0].$full_name[1]\n";





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

Date: Sun, 6 May 2007 16:05:35 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: need a quick script
Message-Id: <slrnf3sgov.4bb.tadmc@tadmc30.august.net>

grocery_stocker <cdalten@gmail.com> wrote:
> On May 6, 3:40 am, Michele Dondi <bik.m...@tiscalinet.it> wrote:
>> On Sun, 06 May 2007 02:27:27 GMT, bob schmo <b...@schmo.com> wrote:
>> >Subject: need a quick script
>>
>> How 'bout a bottle of champagne?  ;-)
>>
>> >Does anyone have a script lying around that will take firstname lastname
>> >and create first initial lastname: Bob Schmo --> BSchmo
>>
>> Nope. I doubt anyone has. It's so easy to write one in a few seconds
>> that there's no reason one should have a similar thing "lying around".
>>
>
> I just tried the doing it now. I took me exactly 17 minutes. 


Yikes!


> The thing
> that slowed me up was if I had the input of say
>
> Chad Altenburg
>
> I needed to figure out how to store the name the characters 'C' 'h'
  ^^^^^^^^^^^
> 'a' 'd' in one array and 'Chad' 'Altenburg' in another array.  


No you didn't.

   perl -le '$_=q(Chad Altenburg); s/^(.)\S+\s+/$1/; print'


> All
> this was due to the fact that I have a poor grasp over regex.


Right.


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


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

Date: Sun, 06 May 2007 23:20:42 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: need a quick script
Message-Id: <5a6v9tF2npf40U1@mid.individual.net>

grocery_stocker wrote:
> On May 6, 9:36 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>>
>>        sub nameconvert {
>>                my ($first, $last) = split ' ', shift;
>>                substr($first, 0, 1) . $last
>>        }
>>
>>        print nameconvert('Chad Altenburg'), "\n";
> 
> Here is perl code I wrote this morning
> 
> #!/usr/bin/perl -w

     use strict;

missing.

> my $line=<stdin>;
> 
> $line =~ s/^\s+//;
> @full_name = split(/\W/, $line);

What if $line contains non-ASCII characters? Those two lines can be 
replaced with

     my @full_name = split ' ', $line;

See "perldoc -f split"

> @first_name = split(//,$line);

No need to create that array. Just use substr() to grasp the first 
character of the first name.

> print "$first_name[0].$full_name[1]\n";

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


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

Date: Sun, 06 May 2007 17:29:47 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: need a quick script
Message-Id: <m24pmpy71w.fsf@local.wv-www.com>

"Lambik" <lambik@kieffer.nl> writes:

> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
> news:5a6elcF2n85heU1@mid.individual.net...
>> grocery_stocker wrote:
>> sub nameconvert {
>> my ($first, $last) = split ' ', shift;
>> substr($first, 0, 1) . $last
>> }
>>
>> print nameconvert('Chad Altenburg'), "\n";
>>
>
> Such a hopeless question and i still learned something. I would have done:
>
> return substr($first, 0, 1) . $last
>
> Didn't know the return was optional

Perl doesn't require it - but the future maintainer(s) of your code (which
includes yourself in six months) will thank you if you write it explicitly
instead of accepting the default return value.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Sun, 06 May 2007 17:36:27 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: need a quick script
Message-Id: <m2zm4hws6c.fsf@local.wv-www.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

> grocery_stocker wrote:
>>
>> @full_name = split(/\W/, $line);
>
> What if $line contains non-ASCII characters?

It shouldn't matter, should it? Assuming that the handle $line was read
from is using the correct encoding layer, and Perl 5.8 or newer, I'd
expect /\W/ to do the right thing with respect to non-ASCII characters.

Am I expecting too much magic?

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Sun, 06 May 2007 17:39:31 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: need a quick script
Message-Id: <m2vef5ws18.fsf@local.wv-www.com>

bob schmo <bob@schmo.com> writes:

> Does anyone have a script lying around that will take firstname
> lastname and create first initial lastname: Bob Schmo --> BSchmo

Careful with that! I worked in an office where we generated logins using
the same scheme. That changed when Sue Hitts needed a login. :-) (First
name changed to protect the innocent.)

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Sun, 06 May 2007 23:48:21 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: need a quick script
Message-Id: <5a70toF2nhqclU1@mid.individual.net>

Sherm Pendley wrote:
> "Lambik" <lambik@kieffer.nl> writes:
>>"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
>>news:5a6elcF2n85heU1@mid.individual.net...
>>>
>>>sub nameconvert {
>>>my ($first, $last) = split ' ', shift;
>>>substr($first, 0, 1) . $last
>>>}
>>>
>>>print nameconvert('Chad Altenburg'), "\n";
>>
>>Such a hopeless question and i still learned something. I would have done:
>>
>>return substr($first, 0, 1) . $last
>>
>>Didn't know the return was optional
> 
> Perl doesn't require it - but the future maintainer(s) of your code (which
> includes yourself in six months) will thank you if you write it explicitly
> instead of accepting the default return value.

More a matter of style, isn't it? After all, this is Perl, not PHP...

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


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

Date: Sun, 06 May 2007 23:48:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: need a quick script
Message-Id: <5a70tsF2nhqclU2@mid.individual.net>

Sherm Pendley wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>>grocery_stocker wrote:
>>>
>>>@full_name = split(/\W/, $line);
>>
>>What if $line contains non-ASCII characters?
> 
> It shouldn't matter, should it? Assuming that the handle $line was read
> from is using the correct encoding layer, and Perl 5.8 or newer, I'd
> expect /\W/ to do the right thing with respect to non-ASCII characters.
> 
> Am I expecting too much magic?

Maybe not, but too many assumptions to my taste. :)

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


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

Date: 6 May 2007 15:10:38 -0700
From: grocery_stocker <cdalten@gmail.com>
Subject: Re: need a quick script
Message-Id: <1178489438.790447.327130@y80g2000hsf.googlegroups.com>

On May 6, 2:36 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> Gunnar Hjalmarsson <nore...@gunnar.cc> writes:
> > grocery_stocker wrote:
>
> >> @full_name = split(/\W/, $line);
>
> > What if $line contains non-ASCII characters?
>
> It shouldn't matter, should it? Assuming that the handle $line was read
> from is using the correct encoding layer, and Perl 5.8 or newer, I'd
> expect /\W/ to do the right thing with respect to non-ASCII characters.
>
> Am I expecting too much magic?
>
> sherm--

Here comes the magic.
[cdalten@localhost perl]$ perl -v

This is perl, v5.8.8 built for i386-linux-thread-multi

Copyright 1987-2006, Larry Wall

When  I run my version...
[cdalten@localhost perl]$ ./name.pl
Chad ;;Altenburg
C.

And when I modify Gunnar's program to
#!/usr/bin/perl -w
use strict;

sub nameconvert{
    my ($first, $last) = split ' ', shift;
    substr($first, 0, 1).$last;
}

print nameconvert('Chad ;;Altenburg'), "\n";

I get
[cdalten@localhost perl]$ ./name2.pl
C;;Altenburg





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

Date: Sun, 06 May 2007 11:30:24 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Populating an array from a mysql select
Message-Id: <060520071130241796%jgibson@mail.arc.nasa.gov>

In article <1178306179.376266.13540@u30g2000hsc.googlegroups.com>,
Nikos <nikos1337@gmail.com> wrote:

> Also this:
> 
> my @titlelist;
> open FILE, "<$ENV{'DOCUMENT_ROOT'}/data/vault/titlelist.txt" or die
> $!;
>      @titlelist = <FILE>;
> close FILE;
> 
> print br() x 3;
> print start_form( action=>'/cgi-bin/admin.pl' );
>   print table( {class=>'user_form'},
>      Tr( td(  'Πές μου τι θα ήθελες:'                   ),
> td( popup_menu( -name=>'title' -values=>\@titlelist ))),

need comma here ----------------^

>      Tr( td(  'Κάτι άλλο που θα ήθελες να σχολιάσεις?'  ),
> td( textarea( -name=>'remark', -rows=>4, -columns=>25 ))),
>      Tr( td(  'Το τηλέφωνο επικοινωνίας σου για επιβεβαίωση
> είναι:'  ),  td( textfield( -name=>'phone' ))),
> 
>      Tr( td(  a( {href=>'/cgi-bin/show.pl?name=showbook'},
> font( {size=>3, color=>'yellow'},  'Εμφάνιση!' ))),
>        td(  submit( 'Αποστολή!' )))
>   );
> 
> 
>       print hidden(-name=>'date',  -value=>$date);
>       print hidden(-name=>'host',  -value=>$host);
> print end_form();
> 
> Although @titlelist is filled with all entries from titlelist.txt
> file(one entry per line), when it gets printed  with popup_menu  it
> displays nothing at all!!
> 

Is that your real code?
Do you have 'use strict;' and 'use warnings;' at the beginning of your
program? If so, Perl would have told you what is wrong (you have a
missing comma).

Please post short but complete programs.
Thanks.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

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 V11 Issue 411
**************************************


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