Re: mech-content match regex howto

2010-03-03 Thread Dr.Ruud

raphael() wrote:


( my $ip ) = $last_page =~ m/[\d.]+/g


The \d matches 200+ codepoints, so if you want to match only 0-9, then 
use [0-9.].


--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: mech-content match regex howto

2010-03-03 Thread raphael()
On Wed, Mar 3, 2010 at 4:17 AM, Dr.Ruud
rvtol+use...@isolution.nlrvtol%2buse...@isolution.nl
 wrote:

 raphael() wrote:

  ( my $ip ) = $last_page =~ m/[\d.]+/g


 The \d matches 200+ codepoints, so if you want to match only 0-9, then use
 [0-9.].

 --
 Ruud


 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/


 Thanks for the advice. [0-9.] it is.


Re: File::Find NO RECURSION Howto

2010-03-03 Thread Shlomi Fish
On Monday 01 Mar 2010 19:31:15 Shawn H Corey wrote:
 Shlomi Fish wrote:
  Well, Matt S. Trout shared his sentiments about I cannot use CPAN here:
  
  http://www.shadowcat.co.uk/blog/matt-s-trout/but-i-cant-use-cpan/
 
 Well, Matt is wrong.  You can't always use CPAN.  Yes, you can set it up
 so you can use it in development, but that doesn't mean you can do it in
 production.  I have worked in places where the policy was no software
 that's not approved by the sysadmins and approval of a single module may
 take 6 to 18 months.  They're even very strict about downloading a copy
 and cut  paste.  A foolish policy, kinda like, our horse will never get
 sick from bad grain if we never feed it but managers _always_ know best. 
 ;)

Heh, tell me about it. Medium-to-large businesses shoot themselves in the foot 
by incorporating these god-awful policies and becoming very non-agile. Then 
they wonder why startups with much fewer resources can often easily out-
compete them. I read somewhere (Paul Graham I think, but I can no longer find 
it) that as companies grow they adopt more and more rules and regulations 
after learning from mistakes they made in the past. But these rules prevent a 
lot of legitimate actions and in turn make the company much less agile. And 
sometimes they impose these rules on start-ups that they buy.

It was later compared to 
http://en.wikipedia.org/wiki/Sarbanes%E2%80%93Oxley_Act which killed the IPOs 
in .us and was another regulation that was passed and which had unwanted side-
effects.

In any case, such antagonism towards using third-party code will make the 
person working for such companies beyond help and doomed anyway you look at 
it, so we can ignore it.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Understand what Open Source is - http://shlom.in/oss-fs

Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Copy files from one machine to another machine

2010-03-03 Thread Irfan Sayed
Hi all,

I need to copy files from one machine to another machine. I need to use 
Net::SCP module .
Can you please give/help me small Perl snippet which will copy the files

Please advice

Regards
Irfan.


  

Re: Controlling one process depending on the status of another

2010-03-03 Thread Jeremiah Foster

On Feb 26, 2010, at 10:34 PM, Eric Veith1 wrote:

 Dear list,
 
 I'm wrinting a perl program that works with different threads.

Your first sentence already has me worried. Threads are un-fun. 

 Those 
 threads depend on each other, not all in the same way. Some threads should 
 stop when others are finished with their work, and again others are to be 
 started afterwards.

Now getting really complex.

 I have six worker machines, M1 to M6, and a controller machine, M0. The 
 perl program runs on the controller machine. This program is basically a 
 dispatcher I control from a command line interface. A command causes two 
 threads to be started, say on M1 and M2.

At this point, these are really processes. Threads are in the kernel, you are 
just starting a separate process on two different machines.

 One thread on M1 produces work, 
 the other on M2 plots the network traffic. When M1 is finished, I want the 
 thread M0 that caused the workload to signal to the dispatcher that M1 is 
 finished. The dispatcher then shall signal M2 to stop monitoring. 
 Afterwards, I want the results from both M1 and M2, preferably in form of 
 a perl structure.

These are all separate processes, not threads. Are you sure you need to use 
threads? In general a thread is something that runs _inside_ a process. 
http://en.wikipedia.org/wiki/Thread_(computer_science)

 First of all, is that possible?

Yes. Not that hard. You have exit values from your process so you can trap that 
and do something based on your exit value.
 
 I have already looked at threads, threads::shared and the traditional 
 fork(). With the standard IPC stuff, I'm able to signal and trap that in 
 the master process with a signal handler. But I cannot, however, get the 
 PID of the child that emitted the signal, thus I'm not able to send a 
 SIGTERM to another process. I'm also not sure how I could get my result 
 data.

Well, why not just create something in a perl structure and just use something 
like the Storable module or YAML to dump it to disk and you can read it from 
your other machine.
 
 threads::shared allows me to share a perl structure I could fill, but I 
 don't know how to signal the master thread. Passing a subroutine reference 
 doesn't work, of other options I don't know.
 
 I'd very much appreciate any hints.

I would avoid threads. I would have a program / process on machine 0 that fires 
off another program / process on machine 1. Then I guess you need to fire off 
your program on machine 2 to do network monitoring (?). When the program on 1 
is finished, it dumps its data to disk and call machine 0 who in turn calls 2.

Jeremiah



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Controlling one process depending on the status of another

2010-03-03 Thread Bob McConnell
From: Jeremiah Foster
 On Feb 26, 2010, at 10:34 PM, Eric Veith1 wrote:
 
 I'm wrinting a perl program that works with different threads.
 
 Your first sentence already has me worried. Threads are un-fun. 
 
 Those 
 threads depend on each other, not all in the same way. Some threads
should 
 stop when others are finished with their work, and again others are
to be 
 started afterwards.
 
 Now getting really complex.
 
 I have six worker machines, M1 to M6, and a controller machine, M0.
The 
 perl program runs on the controller machine. This program is
basically a 
 dispatcher I control from a command line interface. A command causes
two 
 threads to be started, say on M1 and M2.
 
At this point, these are really processes. Threads are in the kernel,
you
 are just starting a separate process on two different machines.
 
 One thread on M1 produces work, 
 the other on M2 plots the network traffic. When M1 is finished, I
want the 
 thread M0 that caused the workload to signal to the dispatcher that
M1 is 
 finished. The dispatcher then shall signal M2 to stop monitoring. 
 Afterwards, I want the results from both M1 and M2, preferably in
form of 
 a perl structure.
 
 These are all separate processes, not threads. Are you sure you need
to
 use threads? In general a thread is something that runs _inside_ a
 process. http://en.wikipedia.org/wiki/Thread_(computer_science)
 
 First of all, is that possible?
 
 Yes. Not that hard. You have exit values from your process so you can
 trap that and do something based on your exit value.
 
 I have already looked at threads, threads::shared and the traditional

 fork(). With the standard IPC stuff, I'm able to signal and trap that
in 
 the master process with a signal handler. But I cannot, however, get
the 
 PID of the child that emitted the signal, thus I'm not able to send a

 SIGTERM to another process. I'm also not sure how I could get my
result 
 data.
 
 Well, why not just create something in a perl structure and just use
 something like the Storable module or YAML to dump it to disk and you
 can read it from your other machine.
 
 threads::shared allows me to share a perl structure I could fill, but
I 
 don't know how to signal the master thread. Passing a subroutine
reference 
 doesn't work, of other options I don't know.
 
 I'd very much appreciate any hints.
 
 I would avoid threads. I would have a program / process on machine 0
 that fires off another program / process on machine 1. Then I guess
 you need to fire off your program on machine 2 to do network
 monitoring (?). When the program on 1 is finished, it dumps its data
 to disk and call machine 0 who in turn calls 2.

Depending on how much control you have over development of this package,
I would suggest a hybrid approach. First, launch an application which
creates multiple threads to start up the individual processes. Open a
communications channel between each thread and the process it called.
Then use the threads to monitor and/or control the individual processes
until they terminate. Once the process is done, terminate the matching
thread.

When processes run on the local machine, any of the IPC options can be
used for the comm channel. On remote machines it is more likely to be a
socket. Interprocess communications can be done either via IPC or
relayed through the control threads.

However, if the application is this complex, is Perl really the best
language to use? It would not be my first choice.

Bob McConnell

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Copy files from one machine to another machine

2010-03-03 Thread Jeff Peng
On Wed, Mar 3, 2010 at 8:40 PM, Irfan Sayed irfan_sayed2...@yahoo.com wrote:
 Hi all,

 I need to copy files from one machine to another machine. I need to use 
 Net::SCP module .
 Can you please give/help me small Perl snippet which will copy the files


I was thinking this module's document has already given the examples.

http://search.cpan.org/~ivan/Net-SCP-0.08/SCP.pm



-- 
Jeff Peng
Email: jeffp...@netzero.net
Skype: compuperson

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




parsing numbers from grep

2010-03-03 Thread Noah


Hi there,

is there a way to easily just get the number itself saved into an array? 
i dont need the 'link' text.


if (@ARGV) {
@link_numbers = grep(/^link([0-9]+)/,@ARGV);
}



Cheers,

Noah

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: parsing numbers from grep

2010-03-03 Thread Uri Guttman
 N == Noah  noah-l...@enabled.com writes:

  N Hi there,

  N is there a way to easily just get the number itself saved into an
  N array? i dont need the 'link' text.

  N if (@ARGV) {
  N @link_numbers = grep(/^link([0-9]+)/,@ARGV);
  N }

just change grep to map and it should work. grep only returns a subset
of its input list. map returns any list it generates given an input
list. in the above code the regex in list mode will return the grabbed
numbers and that is returned by map.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: parsing numbers from grep

2010-03-03 Thread Shawn H Corey
Noah wrote:
 
 Hi there,
 
 is there a way to easily just get the number itself saved into an array?
 i dont need the 'link' text.
 
 if (@ARGV) {
 @link_numbers = grep(/^link([0-9]+)/,@ARGV);
 }

Use the block form:

if (@ARGV) {
  @link_numbers = grep { /^link([0-9]+)/; $_ = $1; } @ARGV;
}

Doesn't work with link0.


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: parsing numbers from grep

2010-03-03 Thread Uri Guttman
 SHC == Shawn H Corey shawnhco...@gmail.com writes:

  SHC Noah wrote:
   
   Hi there,
   
   is there a way to easily just get the number itself saved into an array?
   i dont need the 'link' text.
   
   if (@ARGV) {
   @link_numbers = grep(/^link([0-9]+)/,@ARGV);
   }

  SHC Use the block form:

  SHC if (@ARGV) {
  SHC   @link_numbers = grep { /^link([0-9]+)/; $_ = $1; } @ARGV;
  SHC }

that modifies @ARGV so it is a bad idea. also it bypasses grep's purpose
of filtering a list. and as i posted, map is the correct solution

  SHC Doesn't work with link0.

another reason to not use this solution.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: parsing numbers from grep

2010-03-03 Thread Shawn H Corey
Uri Guttman wrote:
 that modifies @ARGV so it is a bad idea. also it bypasses grep's purpose
 of filtering a list. and as i posted, map is the correct solution

map is not the correct solution since it does not filter out those which
do not match the pattern.  Only grep can do that.


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: parsing numbers from grep

2010-03-03 Thread John W. Krahn

Shawn H Corey wrote:

Uri Guttman wrote:

that modifies @ARGV so it is a bad idea. also it bypasses grep's purpose
of filtering a list. and as i posted, map is the correct solution


map is not the correct solution since it does not filter out those which
do not match the pattern.  Only grep can do that.


Did you actually try it?  I didn't think so.

$ perl -le'
@ARGV = map link$_, 0, 1, xx, [], 666, 99, -5;
print \...@argv = @ARGV;
my @link_numbers = grep { /^link([0-9]+)/; $_ = $1; } @ARGV;
print \...@argv = @ARGV\n . @link_numbers . : @link_numbers;
'
@ARGV = link0 link1 linkxx link[] link666 link99 link-5
@ARGV = 0 1   666 99
3: 1 666 99

$ perl -le'
@ARGV = map link$_, 0, 1, xx, [], 666, 99, -5;
print \...@argv = @ARGV;
my @link_numbers = map /^link([0-9]+)/, @ARGV;
print \...@argv = @ARGV\n . @link_numbers . : @link_numbers;
'
@ARGV = link0 link1 linkxx link[] link666 link99 link-5
@ARGV = link0 link1 linkxx link[] link666 link99 link-5
4: 0 1 666 99



John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.   -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: parsing numbers from grep

2010-03-03 Thread Uri Guttman
 SHC == Shawn H Corey shawnhco...@gmail.com writes:

  SHC Uri Guttman wrote:
   that modifies @ARGV so it is a bad idea. also it bypasses grep's purpose
   of filtering a list. and as i posted, map is the correct solution

  SHC map is not the correct solution since it does not filter out those which
  SHC do not match the pattern.  Only grep can do that.

map will return what is grabbed in $1. if the pattern doesn't match,
nothing is grabbed so it will not return anything for that list element.

perl -le 'print join -, map /x(\d+)/, qw(x123 y123 x x234)'
123-234

just what the doctor ordered! :)

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/