Re: How to split a string read from the file?

2006-03-30 Thread Gerard Robin
I am off topic regarding your question about split, but with a one-liner like this perl does the work for you: perl -pi~ -e 's/^\d+ *: *//' file.txt hth -- Gérard -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

how to save a value ?

2006-03-22 Thread Gerard Robin
Hello, this script does what is expected : #!/usr/bin/perl use warnings; # use strict; &matrix_read_file; print "@$_\n" foreach @MAT1; print "@$_\n" foreach @$matrix_name; sub matrix_read_file { while (my $line = ) { chomp $line; next if $line =~ /^\s*$/; if ($l

Re: file test

2006-01-24 Thread Gerard Robin
On Mon, Jan 23, 2006 at 09:47:40PM +0100, hien wrote: > i am trying to check if there are any files named file* (e.g. > file_001.txt file1.doc) in my directory. #!/usr/bin/perl use warnings; use strict; my $i = 0; while () { if (-e $_) { print "$_ exists\n"; $i++; } } print "there are $i f

Re: negative match

2006-01-20 Thread Gerard Robin
On Fri, Jan 20, 2006 at 04:22:28PM +0100, Adriano Allora wrote: From: Adriano Allora <[EMAIL PROTECTED]> I've got this four rows (for instance): arabaADJ arabo araboADJ arabo araboNOM arabo aranoVER:presarare and, with this regular expression, I would extr

dprofpp

2006-01-13 Thread Gerard Robin
Hello, I am runing an example (in Debbugging Perl of Martin Brown) there are two scripts which product the same output but one contains three subroutines and the other only one subroutine. The outputs: "3 subroutines" ~~ Total Elapsed Time = 0.199198 Seconds User+System Time = 0.02

Re: pack an array

2006-01-02 Thread Gerard Robin
On Mon, Jan 02, 2006 at 10:07:44AM -0800, Tom Phoenix wrote: my @pack; my $empties = 0; foreach my $item (@array) { if ($item eq '') {# empty string $empties++; } else { push @pack, $item; } } Thanks, very nice. It's difficult (for me ;-)) to think in P

pack an array

2006-01-02 Thread Gerard Robin
Hello, I guess that one can write in more perlish fashion that I did: the part between the of this script to pack the array @array. Please, can someone give me some hint ? #!/usr/bin/perl # pack_array.pl use strict; use warnings; my $string = "[EMAIL PROTECTED] n??e#w [?! \$ \% y]e{?]a#

Re: getting a time diff from strings

2005-12-29 Thread Gerard Robin
On Wed, Dec 28, 2005 at 09:18:55PM -0500, Robert wrote: From: Robert <[EMAIL PROTECTED]> To: beginners@perl.org Subject: getting a time diff from strings I have a log that I am parsing and I can get the login and logout time string parsed out. It looks like this: 13:50:01# this is the w

Re: From column to row?

2005-11-28 Thread Gerard Robin
On Mon, Nov 28, 2005 at 08:45:14PM +0100 Andrej Kastrin wrote: > Hi, I am totally NOOB in Perl and here is my first problem, which I > couldn't solve... > I have column data in file xy.txt, which looks like: > A > B > C > ABCDD > .. > . > > Now I have to transform this to row data fil

Re: How recognize strange subject in a mail ?

2005-11-25 Thread Gerard Robin
On Thu, Nov 24, 2005 at 09:32:41PM -0500 Chris Devers wrote: > On Fri, 25 Nov 2005, Gerard Robin wrote: > > > Can someone give me some advices to recognize such subject if it's > > possible. > > Yes, it's possible. The solution is already available, it'

How recognize strange subject in a mail ?

2005-11-24 Thread Gerard Robin
Hello, I wrote an amateurish script perl (I use Net::POP3) to block the spam which (the script) runs fairly fine. But I got a mail with that header: (in gnome-terminal) From: [EMAIL PROTECTED] Subject: To: [EMAIL PROTECTED] And my script did not work, while currently it worked fine with an emp

Re: regex

2005-11-17 Thread Gerard Robin
On Wed, Nov 16, 2005 at 04:57:30PM -0500 Jay Savage wrote: > On 11/16/05, Gerard Robin <[EMAIL PROTECTED]> wrote: > > On Wed, Nov 16, 2005 at 05:17:29AM -0800 John W. Krahn wrote: > > > > > The first one should be faster. Of course you could use the Benchmark >

Re: regex

2005-11-16 Thread Gerard Robin
On Wed, Nov 16, 2005 at 05:17:29AM -0800 John W. Krahn wrote: > The first one should be faster. Of course you could use the Benchmark module > to find out for sure. Thanks for your help. I tried Benchmark but the results seem not reliable: cmpthese( -5, { a => sub{$x*$x}, b => sub{$x**2} } )

regex

2005-11-16 Thread Gerard Robin
Hello, in a script I can write: if ( $subject =~ /phar/i or $subject =~ /phfar/i or $subject =~ /phhar/i or $subject =~ /phya/i or $subject =~ /photo/i ){..} "or" if ( $subject =~ /ph(ar|far|har|ya|oto)/i ){...} "or" if ( $subject =~ qr(ph(ar|far|har|ya|oto))i )

print main:: ....

2005-10-13 Thread Gerard Robin
Hello, when I run this script I get the results: #!/usr/bin/perl #obj1.pl # package Useless; use warnings; sub method { return "sometimes I don't understand Perl and often I am wrong" } my $obj = bless []; print main::method, "\n"; print main::, "\n"; print $obj, "\n"; print $obj->method, "\n"

Re: use strict, aliases, local

2005-10-02 Thread Gerard Robin
On Sun, Oct 02, 2005 at 08:49:30AM -0400 Jeff 'japhy' Pinyan wrote: ... > > If you REALLY want to use package variables instead of lexicals, then you > need to follow the instructions in the 'strict' documentation for > declaring your global variables: > > use strict; > our

use strict, aliases, local

2005-10-02 Thread Gerard Robin
Hello, when I try this example for aliases: use warnings; # use strict; $foo = 26; @foo = ("here's", "a", "list"); &testsub (*foo); print ("The value of \$foo is now $foo\n"); sub testsub { local (*printarray) = @_; foreach $element ( @printarray) { print ("$element\n"); } $printarray = 61;

Re: generating a wordlist from an array of arrays

2005-09-29 Thread Gerard Robin
On Thu, Sep 29, 2005 at 07:26:51PM +0200 mark berger wrote: > hey list. i stuck with gererating a wordlist from a changing > multidimensional array. each entry in the array contains a list with the > possible values. > > fe: > > @wordlayout = ((a, b),# possible values for 1st char

Re: problems with getpwent

2005-09-17 Thread Gerard Robin
On Sat, Sep 17, 2005 at 08:20:55PM +0530 Binish A R wrote: > Hello, > > I've a doubt with getpwent function. > The following code [ getpwent in list context ] is getting into an infinite > loop: > #!/usr/bin/perl -l > > > while ($ref = [ getpwent() ]) { > last unless @$ref;

array or hash ?

2005-09-08 Thread Gerard Robin
hello, In a array @tab I get $tab[n], but I don't know n. I want to get $tab[n + 1]. I found two ways (there are probably better ways;-)) 1: @tab = qw/bar tabou island mong turlut foo perl/; ($mot1) = grep /tu/, @tab; print $mot1, "\n"; $index = 0; foreach (@tab) { last if $tab[$index] eq $mot1

Re: catchDate

2005-09-08 Thread Gerard Robin
On Thu, Sep 08, 2005 at 01:25:18AM -0700 Christopher Spears wrote: > I want to catch the various parts of the output of the > date command. Here is my script: > > #!/usr/bin/perl -w > use strict; > > my $date = system("date"); with: my $date = localtime; woks fine. > What is going on? Does

Net::POP3

2005-09-07 Thread Gerard Robin
Hello, I use Net::POP3 for donwload the header of my messages. . $pop = Net::POP3->new($server); ... $top = $pop->top($msgnum); ... my ($from) = grep /^From:/i, @lines; my ($to) = grep /^To:/i, @lines; my ($subject) = grep /^Subject:/i, @lines; ... When To is: To: beginners@perl.or

Re: Perl examples

2005-08-24 Thread Gerard Robin
On Tue, Aug 23, 2005 at 02:14:25PM -0700 anu p wrote: > > It would be great if any one can suggest me some nice > websites which have good practical perl examples. http://www.sthomas.net/oldpages/roberts-perl-tutorial.htm http://www.netcat.co.uk/rob/perl/win32perltut.html http://www.cclabs.misso

Re: slices of hashes

2005-07-21 Thread Gerard Robin
On Thu, Jul 21, 2005 at 04:04:36PM -0400 Scott R. Godin wrote: > Gerard Robin wrote: > >Hello, > >the slices of hashes work strangely ... > > > > >PS > >if I write: > >@h3{"Mamadoo".."Lulu"} = (30, 40, 50 ); > >the script hangs

slices of hashes

2005-07-21 Thread Gerard Robin
Hello, the slices of hashes work strangely ... The parts 1, 2 and 4 work fine; but the part 3 doesn't do what I expect. What is wrong in what I do in part 3 ? #!/usr/bin/perl #slice3.pl use warnings; use strict; # 1 my %h1 = (a => 1, b => 2, c => 3, d => 4, e => 5, f => 6); print sort {$a <=>

Re: each

2005-07-13 Thread Gerard Robin
On Wed, Jul 13, 2005 at 11:53:33AM -0700 John W. Krahn wrote: .. .. > You have two keys in the hash and you are calling each() twice which does > not > reset the iterator. You need to reset the iterator by either calling each() > until it returns nothing (undef) or by calling keys() or v

each

2005-07-13 Thread Gerard Robin
Hello, with perl 5.8 with this script: #!/usr/bin/perl #hash2.pl use warnings; use strict; my %where=( London => "England", Madrid => "Spain", ); print "-"x20, "\n"; my ($a, $b) = each %where; my ($c, $d) = each %where; print "$a $b\n"; print "$c $d\n"; pr

Re: "sort" usage in arrays

2005-07-06 Thread Gerard Robin
On Mon, Jul 04, 2005 at 08:34:26PM + Vineet Pande wrote: > Hello! > In the following code: > > ** > #!/usr/bin/perl > use warnings; > use strict; > my @unsorted = (1, 2, 11, 24, 3, 36, 40, 4); > my @number = sort { $a <=> $b } @unsorted; > print

Re: Programming exercises

2005-04-19 Thread Gerard Robin
On Mon, Apr 18, 2005 at 06:47:44PM +0100 Stephen Day wrote: > > Hello, > > Does anyone know of a website that lists some programming exercises to help in > learning perl? > > I find it a lot easier to learning a language if I have exercises to apply it > to. I don't know if I reply exactly to

Re: Input a password from STDIN

2005-02-06 Thread Gerard Robin
On Sun, Feb 06, 2005 at 10:33:05PM +0800 Xiaofang Zhou wrote: > Anyone can help me in this?. When running > > $password = ; > > the password will show on the console windows as user > type in. Is it possible for perl to read from keyboard > directly, without echo to the console window? there is

Re: remove a file ?

2005-01-30 Thread Gerard Robin
On Mon, Jan 31, 2005 at 05:02:32AM +1000 Alfred Vahau wrote: > Hi, > > perldoc -f unlink > > alfred > > > Gerard Robin wrote: > > > >Can someone tell me how to remove a file in Perl ? Oops ... Sorry Thanks to all who replied to me. -- Gérard

remove a file ?

2005-01-30 Thread Gerard Robin
Hello, I am new on the list and I am sorry if my question is irrelevant with the list. In a program I have to remove a file. I did "perdoc perlfunc" and I found Functions for filehandles, files, or directories "-X", "chdir", "chmod", "chown", "chroot", "fcntl", "glob", "ioctl", "link", "