Re: regex question

2007-05-14 Thread Igor Sutton Lopes
\s+ (.*) )? $/smx; Good luck! -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: Sorting dir output

2007-04-10 Thread Igor Sutton Lopes
me '*' to remove the current directory. File::Find::Rule->directory()->maxdepth(1)->name('*')->exec ( \&move_file ) ->in($basedir); Sorry for the erroneous code before. -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: Sorting dir output

2007-04-10 Thread Igor Sutton Lopes
story', $_ ) ) or warn $!; } my $rule = File::Find::Rule->new; $rule->directory()->name('trunk')->exec( \&move_file )->in($basedir); -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: Can I map this

2007-04-04 Thread Igor Sutton Lopes
On 2007/04/04, at 18:12, Randal L. Schwartz wrote: "Igor" == Igor Sutton Lopes <[EMAIL PROTECTED]> writes: Igor> my $str = join( " ", map { s/\B(\w+)/\L\1/; $_ } split( / \s+/, $_ ) ); It's bad style to modify $_ in a map, because that also m

Re: Can I map this

2007-04-04 Thread Igor Sutton Lopes
THREE A-HYPENED NAME This was discussed sometime ago on Lisbon.pm :-) while () { my $str = join( " ", map { s/\B(\w+)/\L\1/; $_ } split( /\s+/, $_ ) ); print "str = $str\n"; } __DATA__ SOME NAME SOMEONE WITH FOUR NAMES ONE WITH THREE A-HYPENED NAME -- Ig

Re: Using case in Perl

2007-04-04 Thread Igor Sutton Lopes
; exit; } } sub stop { ... } my %functions = ( start => \&start, stop => \&stop, ... ); $functions{$ARGV[0]}->(); This approach is called 'dispatch table' and is very common on Perl code. Good luck! -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: use lib

2007-04-02 Thread Igor Sutton Lopes
ll that on usual Perl include path when done. -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: Not an ARRAY reference. Problems reading a simple XML file

2007-04-02 Thread Igor Sutton Lopes
low should do what you want. $xml = new XML::Simple( KeyAttr => [], ForceArray => [qw/RECORD/] ); -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: Trying to make things portable

2007-04-02 Thread Igor Sutton Lopes
File::Spec. It has functions to deal with those problems. -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: Dealing with ar archives

2007-03-19 Thread Igor Sutton Lopes
all a couple of prerequisites modules and spend your time doing something fun :-) -- Igor Sutton [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Files Operations in Pearl

2007-03-16 Thread Igor Sutton Lopes
r 1, so please check out. For more information about the above code: $ perldoc strict $ perldoc warnings $ perldoc perlsyn $ perldoc perlfunc -- Igor Sutton [EMAIL PROTECTED]

Re: Dealing with ar archives

2007-03-16 Thread Igor Sutton Lopes
ink it's finally the best option. Why don't you want to use the Archive::Ar module? There's some problems with module's installation or something like that? Just curious about :-) -- Igor Sutton [EMAIL PROTECTED]

Re: Matching the domain of a URL

2007-03-15 Thread Igor Sutton Lopes
On 2007/03/15, at 18:29, Jenda Krynicky wrote: From: Igor Sutton Lopes <[EMAIL PROTECTED]> my @possible_values = qw{ http://www.google.com https://my.domain. http://some.other.domain.net }; my @urls = qw{ http://www.google.com/?some_bizarre_args https://my.domain.com

Re: polling a directory

2007-03-14 Thread Igor Sutton Lopes
s documentation. -- Igor Sutton [EMAIL PROTECTED]

Re: Matching the domain of a URL

2007-03-14 Thread Igor Sutton Lopes
http://some.other.domain.net }; my $regex = '(' . join( "|", @possible_values ) . ')'; foreach my $url (@urls) { if ( $url =~ /$regex/ ) { print "$url matches!\n"; } } -- Igor Sutton [EMAIL PROTECTED]

Re: Perl-based content managers

2007-03-14 Thread Igor Sutton Lopes
can try the Slash[1], which is the same that Slashdot runs, if you like it. There's another I can't remember the name right now, but it would not be difficult to find on a Google search. [1] http://www.slashcode.com/ -- Igor Sutton [EMAIL PROTECTED]

Re: Perl-based content managers

2007-03-14 Thread Igor Sutton Lopes
//www.twiki.org/ [2] http://www.bricolage.cc/ -- Igor Sutton [EMAIL PROTECTED]

Re: How to revinent wget?

2007-03-14 Thread Igor Sutton Lopes
wnload them all? Assuming such a script does not exist, can someone recommend a good set of packages and functions I would use to reinvent wget? You can use WWW::Mechanize for browsing the pages and discover the ISO's url and then LWP for grab them. -- Igor Sutton [EMAIL PROTECTED]

Re: Matching the domain of a URL

2007-03-14 Thread Igor Sutton Lopes
On 2007/03/14, at 15:55, Jeff Pang wrote: Hello, I just think regex is the best way since you choose to use Perl doing this work. Regexp::Common::URI may be what you're looking for. -- Igor Sutton [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional com

Re: URL too long

2007-02-28 Thread Igor Sutton Lopes
sage, and the concerning lines of your script? -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: array operation

2007-02-26 Thread Igor Sutton Lopes
ay and slice val- ues interpolated into a double-quoted string (or similar inter- preted string). Default is a space. (Mnemonic: obvious, I think.) HTH! -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

Re: array operation

2007-02-26 Thread Igor Sutton Lopes
Hi, On 2007/02/26, at 10:12, John W. Krahn wrote: print map "$_\n", @test; print "$_\n" for @test; Another solution is setting the $" variable: my @array = qw(1 2 3 4 5); { local $" = "\n"; print "@array"; } HTH! -- Igor Sutto

Re: Home directory

2007-02-26 Thread Igor Sutton Lopes
directory. such as: C:\Documents and Settings\yantao USERPROFILE is the environment variable. You can also use the File::HomeDir module, that implements the abstraction for those operational systems. HTH! -- Igor Sutton Lopes <[EMAIL PROTECTED]> P

Re: 2 modules share each other's methods, is that safe ?

2007-02-22 Thread Igor Sutton
kA); sub do_specific_thing { my ($self) = @_; my $data = $self->{B}->do_other_thing($self); # see, $self is PackAA instead. ... } HTH! -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Perl DBI Oracle: bind an array list

2007-02-16 Thread Igor Sutton
uot; . join( ",", map { "?" } @list ) . ")"; print $query, "\n"; Then you can do this: $sth->prepare($query); $sth->execute (@list); HTH! -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Dynamically calling a subroutine

2007-02-13 Thread Igor Sutton
Ana, 2007/2/13, Ana Saiz GarcĂ­a <[EMAIL PROTECTED]>: Thank you all for your answers, they have been very helpful :o) It would be nice if you post the solution you picked. It is useful for another user like you to search in archives :-) -- Igor Sutton Lopes <[EMAIL PROTECTED

Re: Dynamically calling a subroutine

2007-02-13 Thread Igor Sutton
ckage Application; use Module::Pluggable require => 1; package main; foreach my $plugin ( Application->plugins() ) { if ( my $code = $plugin->can("my_routine") ) { $code->(); } } HTH! -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail:

Re: Dynamically calling a subroutine

2007-02-13 Thread Igor Sutton
gin::A; sub my_routine { print __PACKAGE__, "::my_routine()\n"; } ^D $ cat > Application/Plugin/B.pm package Application::Plugin::B; sub my_routine { print __PACKAGE__, "::my_routine()\n"; } ^D $ perl module-pluggable-sample.pm Application::Plugin::A::my_routine() Application::

Re: Dynamically calling a subroutine

2007-02-12 Thread Igor Sutton Lopes
ackage main; my $function_name = "some_function"; if (my $coderef = M->can($function_name)) { $coderef->(); } Good luck! -- Igor Sutton Lopes <[EMAIL PROTECTED]> PGP.sig Description: This is a digitally signed message part

while(1) or redo [was: Re: IPC problem]

2007-02-05 Thread Igor Sutton
Hi fellows, Dave, you wanted to use while (1) { ... the code to be repeated .. } The above code could be written like this: { ... # the code to be repeated ... redo; } Do you think this is better or worse than the other idiom? I like the last more. -- Igor Sutton

Re: Removing file extension

2007-01-23 Thread Igor Sutton Lopes
); my $filepath = "/tmp/something.txt"; my ($name, $path, $suffix) = fileparse($filepath, @suffix); HTH! -- Igor Sutton [EMAIL PROTECTED] PGP.sig Description: This is a digitally signed message part

XML::Rules tests [was: Re: XML::LibXML navigation]

2007-01-22 Thread Igor Sutton
s.pm))); Keep up the good work :) -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: files download and performance

2007-01-22 Thread Igor Sutton
sider the network traffic going from your computer to destination. Probably the time you're seen is due to connection delay. I told you the last message that one of the causes would be DNS query, and told you how to cache it, but it is not the only bottleneck you may get. HTH! -- Igor Sutton L

Re: files download and performance

2007-01-22 Thread Igor Sutton
t.uspto.gov/netacgi/nph-Parser?";; my $uri = URI->new($url); print $uri->host, "\n"; HTH! -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: files download and performance

2007-01-22 Thread Igor Sutton
m_hostname("www.google.com"); $t->stop('get_ip_from_hostname without memoize'); } print $t->report(); $t->reset(); memoize('get_ip_from_hostname'); for ( 1 .. 1000 ) { $t->start('get_ip_from_hostname memoize'); my $ip = get_ip_from_ho

Re: files download and performance

2007-01-22 Thread Igor Sutton
out of 70.000 files have been downloaded) You can use the awesome XML::RSS module to create RSS. Now, for database insert you have the excellent DBI module. I bet Java is your problem there (no, I'm not initiating a language war here). -- Igor Sutton Lopes <[EMAIL PROTECTED]> --

Re: files download and performance

2007-01-22 Thread Igor Sutton
mpose the filename # from url. } open my $input, "<", $filename or die $!; while (my $url = <$input>) { chomp($url); my $content = get($url); if ($content) { open my $output, ">", filename_from_url($url) or die $!; print {$output} $content;

Re: putting ";" as a replacement in the substitution.

2007-01-22 Thread Igor Sutton
# skip comments my ($capture) = /^(\w+)\s+/; # grab first 'word' ... } I also like to point that you still can match $some_var like this: my ($capture) = $some_var =~ m/^(\w+)\s+/; Example: while (my $some_var = ) { next if $some_var =~ /^#/; my ($capture) = $some_var

Re: exec and pipe

2007-01-19 Thread Igor Sutton
et::SSH::Perl[2] to invoke procmail on remote host. I think it is the best start, then you could improve it. [1] http://search.cpan.org/~dbrobins/Net-SFTP-0.10/lib/Net/SFTP.pm [2] http://search.cpan.org/~dbrobins/Net-SSH-Perl-1.30/lib/Net/SSH/Perl.pm HTH! -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Pattern Matching

2007-01-19 Thread Igor Sutton
I have an update: my @data = $string =~ m/0x(\d{2})/g; my @data = $string =~ m/0x(\S{2}),?/g; Now I think it is right :) -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Pattern Matching

2007-01-19 Thread Igor Sutton
iable. I need to pull out only the numbers and store them in a array. Like: @array = (53, 65, 63, 75, 72, 69, 74, 79, 43, 6F, 64, 65, 00); I've achieved this results with the following code: my @data = $string =~ m/0x(\d{2})/g; I don't know if it is the most efficient way to do that.

Re: Searching hash if a given value exists

2007-01-19 Thread Igor Sutton
%hash ) { if ( $hash{$_} eq 'house' ) { return 1; } } } my $results = timethese( 100, { reverse_hash => \&reverse_hash, foreach_hash => \&foreach_hash, } ); cmpthese($results) Maybe I'm doing the Ben

Re: Searching hash if a given value exists

2007-01-19 Thread Igor Sutton
ash => \&foreach_hash, } ); cmpthese($results) Maybe I'm doing the Benchmark in a wrong way, or is really more expensive reversing a hash than iterating its keys using foreach? -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Capturing stdout and stderr without redirection

2007-01-18 Thread Igor Sutton
'some cmd and args', 'optarg', ...); HTH! -- Igor Sutton Lopes <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Regex question

2007-01-04 Thread Igor Sutton
s right, because URI gives you the host part of uri. What is the problem you are trying to solve? -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: Regex question

2007-01-04 Thread Igor Sutton
s for any pointers, Mike Why don't you use the URI module for that? use strict; use warnings; use URI; while () { my $uri = URI->new($_); print $uri->host, "\n"; } HTH. -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: detecting a UTF-8 string

2007-01-03 Thread Igor Sutton
2007/1/3, Octavian Rasnita <[EMAIL PROTECTED]>: Hi, I want to check if a certain string is UTF-8 or not. Maybe you want Encode::Guess[1]. [1] http://search.cpan.org/~dankogai/Encode-2.18/lib/Encode/Guess.pm -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: HoA building

2006-12-28 Thread Igor Sutton
uot; $VAR1 = [ '', 'one', 'two', 'three', 'four' ]; [EMAIL PROTECTED] ~]$ perl -MData::Dumper -le "@foo = split ' ', qq( one two three\t\n four ); print Dumper [EMAIL PROTECTED];&quo

Re: HoA building

2006-12-28 Thread Igor Sutton
behav- ior, whereas "split(/ /)" will give you as many null initial fields as there are leading spaces. A "split" on "/\s+/" is like a "split(' ')" except that any leading whitespace produces a null first field. A "split" with no arguments really does a "split(' ', $_)" internally. HTH -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: Strange problem with glob <>

2006-12-28 Thread Igor Sutton
d or Getopt::Long modules, instead of writing your own argument parser. For resolving your file search problem, I suggest the File::Find or File::Find::Rule modules instead. glob can give you headaches, and it doesn't support regexes, just shell like substitution. HTH -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: Capture remsh output

2006-12-20 Thread Igor Sutton
d, and then Net::SSH::Perl[1] comes to rescue you. [1] http://search.cpan.org/~dbrobins/Net-SSH-Perl-1.30/lib/Net/SSH/Perl.pm Hope this helps! -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: Can't get Sudo.pm to run my command but it works from a prompt

2006-10-05 Thread Igor Sutton
es is mentioned in sudoers file. -- Igor Sutton [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>

Re: Imlib2 Module install failure problem

2006-10-05 Thread Igor Sutton
your CPAN shell, then execute the command look "look Image::Imlib2". Then 'perl Makefile.PL; make; make test; make install'. -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: getting a 2 digit readout no matter what

2006-10-04 Thread Igor Sutton
uot;0". And it prints output correctly, but not assigning it to my string. By the way, if you want to know how to get the output of some external command, you can check the qx// operator, that works the same as backticks. $string = `date`; Remember this approach is not portable. -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: Smart assignment

2006-10-03 Thread Igor Sutton
ll be tight with ( $projection =~ ... ) because it has higher precedence than 'or'. The way you wrote it will assign "(missing)" to $ptype, then $ptype's value to $ptype again. It works but not the way you think. Maybe someone could correct me :-) ? -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: why Perl complaints my script

2006-09-28 Thread Igor Sutton
exical scope of for. Maybe someone could explain this better? -- Igor Sutton Lopes <[EMAIL PROTECTED]>

Re: Newbie Question

2006-09-19 Thread Igor Sutton
while ($string != m/[a-zA-Z]{1,5}/ ) { print("that is wrongtry again: "); chomp ($string = ); } Maybe: while ($string !~ m/.../) { ... } When you're matching against regular expressions, you need to use =~ or !~. Hope this helps. -- Igor Sutton Lopes t: +55

Re: extracting line between words

2006-09-14 Thread Igor Sutton
while(<@line>){ print if $_ =~ /The/ .. /east/ ; I suggest this: print join " ", (grep { /The/ .. /east/ } <@line>); -- Igor Sutton Lopes t: +55 51 9627.0779 e: [EMAIL PROTECTED]

Re: Command line vs. cron

2006-09-13 Thread Igor Sutton
There's some reason to not use Proc::ProcessTable? It is really easy to use, and doesnt' relies on environment variables to be used. -- Igor Sutton Lopes t: +55 51 9627.0779 e: [EMAIL PROTECTED]

Re: about map usage

2006-09-13 Thread Igor Sutton
my %hash = map { $_, 1 } @array; What is the usage of 1 in this code? When you have any kind of doubt about a Perl structure, you can use Data::Dumper: use Data::Dumper; my %hash = map { $_, 1 } @array; print Dumper \%hash; Try it! -- Igor Sutton Lopes t: +55 51 9627.0779 e: [EMAIL

Re: Re unexpected result

2006-09-10 Thread Igor Sutton
/^((?:\d+\.){3})(\d+)$/ $2 will match the last entry of $1, unles s you use (?:). Now, $1 should be the first three octets, and $2 should be the last octet. -- Igor Sutton Lopes t: +55 51 9627.0779 e: [EMAIL PROTECTED]

RES: Hash Question

2002-12-06 Thread Igor Sutton Lopes
You can do something like this: %url_options_hash = ("times_visited"=>0); %url_hash = ("this_url"=>\%url_options_hash); %usr_hash = ("igor"=>\%url_hash); print $usr_hash{"igor"}->{"this_url"}->{"times_visited"}, "\n"; $usr_hash{"igor"}->{"this_url"}->{"times_visited"} = 1; print $