Re: Test automation using perl or shell

2013-09-10 Thread Michael Rasmussen
On Tue, Sep 10, 2013 at 01:25:22AM -0700, Lalit Deshmukh wrote:
 i have implemented 50 shell program to test. now i want to run all these
 shell program one by one(in short test automation) (once first program
 getting executed then next will start). please let me know how to do this?
 in UNIX any utility or to run the same.

If you have loops in your shell:
(bash example, assumes the test programs are named t1.sh, t2.sh ... t50.sh)

for TEST in  t*sh
do  ./$TEST
done

in Perl, call with names of the test programs. 
#!/usr/bin/perl
use strict;
use warnings;

foreach my $test (@ARGV) {
system ./$test;
}

-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
It's the HoHo in HoHoHo!

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




Re: Filtering Characters

2013-09-03 Thread Michael Rasmussen
On Wed, Sep 04, 2013 at 02:31:30AM +0100, Rob Dixon wrote:
 Matt matt.mailingli...@gmail.com wrote:
 I have this:
 
 while (IN) {
 chomp;
 next if /^#/;
 # do stuff
 }
 
 
 It skips to the next item in the while loop of the string begins with
 # and works fine.  I would also like to skip to the next item in the
 loop if the string contains anything other then lowercase,
 underscores, numbers, dashes, periods, and spaces.  I do not want
 uppercase characters and any sort of other special characters.  How
 would I do that?
 
 The solution from John Krahn is superior by far, and there is no need for any 
 other suggestions.

John's solution:
next if /[^[:lower:]_\d\-. ]/;


Doesn't work in this test environment:
michael@bivy:~$ cat tpl  ./tpl
#!/usr/bin/perl
use strict;
use warnings;

print \nJohn's solution\n;
while(DATA) {
print Seen line: $_;
next if /[^[:lower:]_\d\-. ]/;
print;
}

__DATA__
a good line
Testing John code
a #!! should not print line
_ Should be OK line
finish with a printing line

John's solution
Seen line: a good line
Seen line: Testing John code
Seen line: a #!! should not print line
Seen line: _ Should be OK line
Seen line: finish with a printing line


-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
When you don't know what to do, do the work in front of you.
~  Calvin Coolidge

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




Re: Array iterator count

2013-08-10 Thread Michael Rasmussen
On Thu, Aug 08, 2013 at 12:30:10PM -0500, Andy Bach wrote:
 On Thu, Aug 8, 2013 at 12:05 PM, Unknown User 
 knowsuperunkn...@gmail.comwrote:
 
  at any point is it possible to say which element i am handling without
  using a counter?
 
 
 Er, well, if it were an array rather than a list
 my @letters = (a .. z);
 foreach my $letter ( a .. z ) {
if ( $letter eq $letters[4] ) {
 
 but that's sort of silly.

And buggy, consider:
my @timings ( 11, 22, 3, 14, 18, 45, 18, ... 86 );

-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
Great minds discuss ideas, average minds discuss events, small minds discuss 
people.
~ Eleanor Roosevelt

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




Re: Array iterator count

2013-08-10 Thread Michael Rasmussen
On Thu, Aug 08, 2013 at 11:30:29PM -0500, Andy Bach wrote:
  And buggy, consider:
my @timings = ( 11, 22, 3, 14, 18, 45, 18, ... 86 );
 
 Yeah, it's a constraint without a cause. Do you want to treat every 18 in 
 the if  or only the first? Why not use a counter?  Is the data from a list, 
 a file or … ? Do we know it's the 5th element ahead of time?
 
 But it seems like there'd have to be something else involved that eliminates 
 a counter var. 
 
I'm not sure if the original poster can't use a counter or was asking if there 
was an automagic indicator.
This example shows one reason why a counter isn't a bad thing.

-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
We'll sit around talking about the good old days, when we wished that we were 
dead.
~  Samuel Beckett on the afterlife

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




Re: using join

2013-08-04 Thread Michael Rasmussen
On Sun, Aug 04, 2013 at 12:59:29PM +0800, *Shaji Kalidasan* wrote:
 Greetings,
 
 I am facing some difficulty using join to display the array elements
 
 Here is the code snippet
 
 [code]
 use strict;
 use warnings;
 
 my @fruits = qw/apple mango orange banana guava/;
 
 print '[', join '][', @fruits, ']';
 [/code]
 
 How can I make the output to eliminate the last empty square brackets [] 
 using a single print statement. I used two print statements as shown in the 
 code snippet above (#lines are commented out)
 
Limit what join acts on by using parenthesis.
   print '[', join ( '][', @fruits ), ']';

This keeps your closing bracket from being part of the list that join is acting 
upon.

-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
Follow the carrot.
~ http://someoneoncetoldme.com/gallery/14052010

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




Re: Perl and Web Development

2013-06-03 Thread Michael Rasmussen
On Mon, Jun 03, 2013 at 05:30:54PM -0500, Robert Wohlfarth wrote:
 On Mon, Jun 3, 2013 at 5:03 PM, Ivan Torres ping...@gmail.com wrote:
 
  I dont know a book but perl dancer its pretty easy and you can find lots
  of documentation or catalyst
 
  http://www.perldancer.org/documentation
 
 
  On Mon, Jun 3, 2013 at 4:52 PM, Rich Johnson hcir...@gmail.com wrote:
 
  Can anyone recommend a good book to use for building a website using
  Perl? Specifically, I'm looking to build a backend to a mobile app.
  Everything I've been trying to search for seems dated (2005 and earlier).
 
 
 I'll second Catalyst. Start simple, and it's pretty easy to learn.
 
 http://www.catalystframework.org/
 
And I'll second Dancer, simplier, quicker to learn, plenty powerful.

-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
If, as some people think, cycling is so dangerous; 
how did I get to be 78 after about half a million kilometres?
~  Harold Bridge

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




Re: modules

2013-06-03 Thread Michael Rasmussen
On Tue, Jun 04, 2013 at 12:01:09AM +0100, Rahim Fakir wrote:
 Iam using win 7 64bits, and i downloaded Strawberry, and I use Perl PAckage
 Manager to install modules, insted of Cpan command.
 I know how to install them, but I need instrucions how to use them, step by
 step, how-to run the modules.
 Best regards
 Ray

Hi Ray,

So, I assume you downloaded whatever modules you chose to because you wanted 
the whatever functionality they provide.  Since I don't know _what_ modules 
you chose I'll give an imaginary example and then a specific example from a 
favorite module I use.

  Having said that:
The CPAN page for a module always includes a SYNOPSIS - this gives a very terse
example of using the module.  Check there.

For our example I'll use the fictional raspberry.pm.
It's synopsis reads;
   use raspberry;
   my $answer = raspberry();

The description says:
raspberry returns a line from the raspberry wisdom list.

In your code then it might be used:

#!/usr/bin/perl
use warnings;
use strict;
use raspberry;   # the use line incorporates the module code into your 
program

my $answer = raspberry(); # the function call uses code from the module 
that you didn't write

print $answer, $/;

and the output might be something like 

Raspberries are delicious!  Eat some soon to feel good!

Now for a specific, real world example:

#!/usr/bin/perl
use Data::Dumper; 

[ imagine a bunch of code that does something, but you don't quite know 
what]
[ someone else wrote it, and it's now time for you to fix a problem 
]
[ there's a huge complex data structure that hash of arrays or a hash of 
hashes or ...? ]

print Dumper( \%my_hash_with_who_knows_what ):

Because you're using Data::Dumper you didn't have to write a bunch of code to 
figure out
how to interpret Perl data structures, Gurusamy Sarathy did all the hard work.  
All you need to
do is include is module and call it on the hash of convoluted origins to see 
what it really is.

Generically:

use module_name;

# code that calls on the modules functions or OO interfaces as documented.



-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
A sadist is a masochist who follows the Golden Rule.

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




Re: Next subnet

2013-05-26 Thread Michael Rasmussen
On Fri, May 24, 2013 at 03:18:35PM -0400, shawn wilson wrote:
 How do I find the next subnet? This should print 192.168.1.0 the
 second time - it errors:

[code deleted]
Why should it? The Net::IP documentation doesn't provide any information about 
actions that cross the subnet boundry.

Having said that, it seems it doesn't allow that operation.  
And in fact, many of the methods don't work after incrementing, which seems 
wrong to me:

#!/usr/bin/perl
use strict;
use warnings;
use Net::IP;

my @method_types = qw ( ip short binip intip mask last_ip prefixlen size iptype 
reverse_ip );

my $ip = Net::IP-new('192.168.0.0/24');# three lines from your code
print Start ip [ . $ip-ip . ]\n;
print start mask [ . $ip-prefixlen . ]\n;

$ip++;
print After incrementing by 1\n;
show_methods($ip);

$ip-set($ip-last_ip) ;
$ip++ ;
print \nAfter incrementing past last_ip\n;
show_methods($ip);


sub show_methods {
my ($ip) = @_;

print now at  . $ip-ip ,$/;

for my $type ( @method_types) {
if( $ip-$type ) {
print $type : , $ip-$type(), $/;
}
else {
print no more $type\n;
}
}
}


__END__

michael@bivy:~/rmme$ ./tpl
Start ip [192.168.0.0]
start mask [24]
After incrementing by 1
now at 192.168.0.1
ip : 192.168.0.1
short : 192
binip : 110010101001
intip : 3232235521
no more mask
last_ip : 192.168.0.255
no more prefixlen
size : 255
iptype : PRIVATE
no more reverse_ip

After incrementing past last_ip
Can't call method ip on an undefined value at ./tpl line 29.
michael@bivy:~/rmme$ 


 

-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
Only the mediocre are always at their best.
~ Jean Giraudoux, French Novelist
(rephrased as Only the mediorcre are at their best all the time. 
~ G.M. Ford in Who the hell is Wanda Fuca?)

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




Re: Scripts in Padre do not run. Need step-by-step help in setting up, asall current procedures I have found have failed for me.

2013-05-26 Thread Michael Rasmussen
On Sat, May 25, 2013 at 04:19:27PM +0200, Dr.Ruud wrote:
 On 24/05/2013 22:25, Michael Goldsbie wrote:

 [...] I installed DWIM Perl  [...]
 So after downloading and installing it, what's the next step?

 On http://dwimperl.com/ there is a link to 'Perl Tutorial',
 which has a link to 'Introduction 1. Install'.

 It mentions:

 Go ahead, download the exe file and install it on your system. Before  
 doing so, please make sure you don't have any other Perl installed.

 Try 'which perl' on the command prompt. What does it report?

The OP states he's working in a Win7 environment, `which perl` is 
not available there.

-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
If you hear a voice within you say you cannot paint, 
then by all means paint, and that voice will be silenced. 
~ Van Gogh

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




Re: Any alternative for substr() function

2013-04-12 Thread Michael Rasmussen
On Fri, Apr 12, 2013 at 04:53:52PM +0530, kavita kulkarni wrote:
 Thanks all, got many ideas from you..
 
 My script took ~7 min to run with data file of ~50,000 lines with
 substr()/unpack() enabled and same script took ~2 min after disabling
 substr()/unpack().

No one has asked what kind of hardware you're running this on, so I will.

Reading the thread, I created a very simplistic test:

michael@post:~$ wc -l /var/log/mail.info
973819 /var/log/mail.info
michael@post:~$ time  perl -ne '$t = substr $_, 4, 9; $s = substr $_, 11, 
15; print $t,$s,$/;' /var/log/mail.info  /dev/null

real0m2.253s
user0m2.104s
sys 0m0.148s
michael@post:~$ 

Over 970,000 lines processed with substr, extracting two substrings from 
positions described in an
earlier email of yours. Total processing time less than 3 seconds. 

I don't believe substr extracting strings is your bottleneck.  We really could 
use some sample data and code to assist.


-- 
Michael Rasmussen, Portland Oregon  
  Be Appropriate  Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
In general, they do what you want, unless you want consistency.
~ Larry Wall

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




Re: Help required to extract multiple text fields from a text string

2012-05-27 Thread Michael Rasmussen
On Sat, May 26, 2012 at 05:52:19PM +0100, Rob Dixon wrote:
 On 26/05/2012 14:07, pa...@fsmail.net wrote:
 From: Rob Dixonrob.di...@gmx.com
 On 26/05/2012 13:51, pa...@fsmail.net wrote:

  split is slower than the correct regex matching.

 That is complete nonsense. Can you show a benchmark that supports your
 claim?
 I do know, and it is nonsense.

 The benchmark below shows that split is better than twice as fast as a
 regex for the application I have chosen.

 If you can rewrite the program to show a diffferent use of regexes where
 they are faster than an equivalent split then I will take it back.

 Please stop deliberately spreading misinformation.
 cmpthese(-5, {
   split = sub {
 my @array = split ' ', $str;
   },
   regex = sub {
 my @array = $str =~ /\S+/g;
   },
 })

Curious, splitting on single char - what split has been optimized for, the awk 
behavior,
but the regex comparsion is splitting on non-whitespace, the inverse of what 
split is doing.  
Correcting \S to \s returns similar results. 

But that raises the question of what happens when not splitting on the highly 
optimized space scenario.
First, let's see what happens when both split and the regex act on \S:
cmpthese(-5, {
  split = sub {
my @array = split /\S+/, $str;
  },
  regex = sub {
my @array = $str =~ /\S+/g;
  },
})
 Rate regex split
regex 44162/s--   -1%
split 44501/s1%--

Now, what happens if our whitespace is mixed between tabs and spaces:
 Rate regex split
regex 40420/s--  -34%
split 61438/s   52%--

How about the not uncommon case of simple CSV?

#  $str .= ' ' x (rand 10 + 1);
$str .= ,;
# change the /\S+/ to /,/

 Rate regex split
regex 63021/s--   -8%
split 68790/s9%--


Perhaps the lesson is split on whitespace else regex


-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
There are those who listen and those who wait to talk.

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




Re: Help required to extract multiple text fields from a text string

2012-05-27 Thread Michael Rasmussen
On Sun, May 27, 2012 at 07:24:26PM -0700, John W. Krahn wrote:
 Michael Rasmussen wrote:
 [ a bunch of blather, snipped here ]

 The regular expression is not splitting!  It is capturing.
 split removes whitespace.
 The regular expression captures non-whitespace.
 So the two expressions posted above are equivalent.

forehead slap/ note to self: early AM is not the time for posting/


-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Follow the carrot.
~ http://someoneoncetoldme.com/gallery/14052010

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




Re: how to display commands while perl script executing

2012-05-15 Thread Michael Rasmussen
On Tue, May 15, 2012 at 07:40:44AM -0400, sunita.prad...@emc.com wrote:
 Hi
 
 I want to print the command during script execution .
 Example :
 
 ===
 $ls = `ls`;
 
 Print $ls\n;
 ==

A straightforward way to do this is to run your script with the perl debugger:

 perl -d script_name

When it loads you'll see something like:

michael@bivy:~$ perl -d tpl

Loading DB routines from perl5db.pl version 1.32
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(tpl:5):  my %index;   The first executable line of your 
script

Then press n on your keyboard to run the next command:

  DB1 n   
 
main::(tpl:6):  my @file = DATA;

And after that just press ENTER to execute each command in turn. 

As you might imagine you can do other things with the debugger too.

-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Happiness is a path, not a destination.
~ Tay Gillespie by way of Mark Canizaro

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




Re: Template toolkit issue [SOLVED] - mod_perl hosting

2012-05-06 Thread Michael Rasmussen
On Sun, May 06, 2012 at 04:04:49AM +0100, 'lesleyb' wrote:
 +1 on that.  AFAIK, being able to use mod_perl still implies having control of
 Apache and it's config.  I haven't yet heard of a hosting company providing
 mod_perl out there though I'd like to know if there are any.  

There are a few, the largest being pair Networks. 
http://perl.apache.org/help/isps.html


-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
The best book on programming for the layman is Alice in Wonderland;
but that's because it's the best book on anything for the layman.
~  Alan Perlis

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




Re: Recommended config/ini file module?

2012-05-03 Thread Michael Rasmussen

On 2012-05-01 06:43, Manfred Lotz wrote:

On Tue, 1 May 2012 05:57:28 -0700
Michael Rasmussen mich...@jamhome.us wrote:


On Tue, May 01, 2012 at 11:58:46AM +0200, Manfred Lotz wrote:
 Hi there,
 What is a recommended Module for processing config resp. inifile
 formats?

 One important feature I need is to use previously defined entries.

Config::Std uses the .INI format and will preserve your comments in
addition to your previously defined entries. I've found it to be a
very easy to use module.




I started trying out Config::Std which indeed is easy to use but 
didn't

get previously defined vars to work.

I tried this but to no avail.


[Dirs]
basedir : /data/
aroot : ${basedir}/root
broot : $basedir/root


The config file is static and does not interpret itself.

To do what I think you're after would require:

The ini file:
[Dirs]
basedir  : /data/

The Perl program bit to use it:

read_config 'name_of_config.ini' = my %config;

$aroot = $config{Dirs}{basedir} . root;



--
 Michael Rasmussen
   http://www.jamhome.us/
Be Appropriate  Follow Your Curiosity

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




Re: Recommended config/ini file module?

2012-05-01 Thread Michael Rasmussen
On Tue, May 01, 2012 at 11:58:46AM +0200, Manfred Lotz wrote:
 Hi there,
 What is a recommended Module for processing config resp. inifile
 formats?
 
 One important feature I need is to use previously defined entries.

Config::Std uses the .INI format and will preserve your comments in
addition to your previously defined entries. I've found it to be a 
very easy to use module.


-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Dicipline is making the choice between what you want now and what you want 
most. 
~ Anon

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




Re: Problem with unless statement

2012-04-28 Thread Michael Rasmussen
On Sat, Apr 28, 2012 at 12:16:57PM -0400, Shawn H Corey wrote:
 On 12-04-28 12:10 PM, Jim Gibson wrote:

 On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote:

 my $host = 'localhost';

 if ( defined ($mail_field) and ($mail_field ne '') ) {
 $host = $mail_field;
 }

 I would use:

 my $host = $mail_field ? $mail_field : 'localhost' ;



 Well, since $mail_field is not likely to be false unless it's undefined:

 my $host = $mail_field || 'localhost';

Good solution++

Clear, easy to read, easy to understand. 

-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
All that we need to make us happy is something to be enthusiastic about.
~ Albert Einstein

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




Re: PERL CGI, HTML and PHP

2012-04-26 Thread Michael Rasmussen
On Wed, Apr 25, 2012 at 01:51:46PM -0400, Mark Haney wrote:
 I've got, what I hope is a fairly simple problem that someone can point  
 me to the best (or best practices anyway) way to handle it.

 I'm writing a web app that monitors embroidery machines and generates  
 reports on various metrics for the company management.  My issue arises  
 from the fact that I've had to move from a pure perl web interface to  
 PHP for it's additional feature set.  Until now, all my output has been  
 generated by perl CGI scripts and output to STDOUT directly, which is  
 fine, but leaves the report rather sparse looking. (FTR, I'm no web  
 designer, I'm here to make it work, not make it pretty, however, I do  
 have to do some preliminary prettifying.)

 That wasn't a real problem, but now I want to take that output and fold  
 it into the PHP headers and footers I've built to keep from having to  
 rewrite the navigation menus and copyright info and such and I can't  
 quite figure out the best way to do it.

I'm late to the conversation.  Could you describe the page needs without
doing so in terms of php can do?

Navigate menus and copyright info and such sound like standard header/footer
information.  This can easily be handled in Perl.  Even easier if you 
use Template::Toolkit or Mason or fill_in_the_blank templating. 

Navigation menus can be dynamically derived from a data structure defining
previous/next relationships.


 I'd really like to be able to output this report to the browser directly  
 with PHP code in it to match the format of the rest of the interface,  

the PHP generates some HTML, Perl does that well.

 The only way I've come up with is to simply output the report data to  
 disk as an HTML file and then include that output in a PHP page that is  
 correctly formatted.

Again, you haven't described why Perl can't create the same HTML the PHP does.



-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
It's not a problem unless it's chronic.
~  Linda Connor

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




Re: Merging multiple strings

2012-04-25 Thread Michael Rasmussen
On Wed, Apr 25, 2012 at 08:52:52AM -0400, Paul Clark wrote:
 Hi All,
 
 I have a small project that is stumping me aside from using a straight brute 
 force.
 
 I am processing output from an accounting program that is producing some 
 sort of printer control for some 3rd party print processing.   I have 
 several partial lines that have commands to over write the line to create 
 bold type.I need combine the lines:
 
 1Balance Due:
 0Balance Due:$567.23
 0$567.23   Before Due Date:
 0  Before Due Date:   06/15/12
 0 06/15/12
 
 So the output line should be:
 
  Balance Due:$567.23Before Due Date: 06/15/12
 
 
 The problem is the lines can be variable so I cannot just use substr to copy 
 parts of lines.   The brute force was I was going to use is to just create 
 an output array for the line and loop through each line position by position 
 and if the character was not a space, set that position in the output array 
 to the character in the input line.
 
 Any suggestions for a more elegant solution?

Depending on how loosely you define elegent

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

my %lines;
my $start = DATA;
my $line_count;
my $max_len = 0;
while(DATA) {
$max_len = length $_  $max_len  ? length $_ : $max_len;
chomp;
s/\s+$//;
$line_count++;

m/(\s[^\s])/;
my $initial_char = $1;
my $offset = index $_, $initial_char, 1; # 1 to skip the 1/0 at start of 
line
my $length = length $_;
$length -= $offset;
my $string = substr $_, $offset, $length;

$lines{$line_count } = [ $offset, $length, $string];

}

my $output =   x $max_len;
foreach my $i ( sort keys %lines ) {
my ($offset, $length, $str)  = @{$lines{$i}};
# print $offset, $length, $str\n;
if( $str) {
   substr $output, $offset, $length, $str;
}
# print $output,$/;
}
print $output,$/;

__DATA__
1Balance Due:
0Balance Due:$567.23
0$567.23   Before Due Date:
0  Before Due Date:   06/15/12
0 06/15/12


Clean up and elegence left as an exercise for the reader

-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Mirrors should reflect a little before throwing back images.
~  Jean Cocteau

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




Re: Net::SMTP

2012-04-24 Thread Michael Rasmussen

On 2012-04-24 13:17, Somu wrote:

Ok.. Thanks for the info on gmail.
But is there any way to find out such information for other hosts?
Like I have an account at https://ems.sbi.co.in so again how do i do 
for

that?



You use the DNS system, usually with nslookup or dig to an mx lookup 
type.  MX stands for Mail eXchanger.

Examples:
$  dig jamhome.us mx

;  DiG 9.6-ESV-R4-P1  jamhome.us mx
;; global options: +cmd
;; Got answer:
;; -HEADER- opcode: QUERY, status: NOERROR, id: 17630
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;jamhome.us.IN  MX

;; ANSWER SECTION:
jamhome.us. 86400   IN  MX  20 barn.michaelsnet.us.
jamhome.us. 86400   IN  MX  10 post.michaelsnet.us.

;; Query time: 81 msec
;; SERVER: 192.168.151.40#53(192.168.151.40)
;; WHEN: Tue Apr 24 17:57:27 2012
;; MSG SIZE  rcvd: 82



or

$  nslookup

set type=mx
jamhome.us

Server: 192.168.151.40
Address:192.168.151.40#53

Non-authoritative answer:
jamhome.us  mail exchanger = 10 post.michaelsnet.us.
jamhome.us  mail exchanger = 20 barn.michaelsnet.us.




On Tue, Apr 24, 2012 at 10:38 PM, Leo Susanto leosusa...@gmail.com 
wrote:



Gmail is implementing secure SMTP, so plain SMTP won't work.

use Net::SMTP::TLS;

And make sure you are using these information
   Host = 'smtp.gmail.com',
   Hello= 'gmail.com',
   Port = 587,
   User = 'x...@gmail.com',


On Tue, Apr 24, 2012 at 9:57 AM, Somu som@gmail.com wrote:
 SMTP is a Protocol, which uses standard commands to send mail.

 I want to use it. So there is already an implementation written. 
So I'm

not
 going for IO or Sockets..
 I want to make it work.
 Please, I need some workable parameters. Help.
 And it dies, simply. Don't know what goes on beneath the 
surface...



 On Tue, Apr 24, 2012 at 6:26 AM, Michael Rasmussen 
mich...@jamhome.us

wrote:

 On Tue, Apr 24, 2012 at 01:54:15AM +0530, Somu wrote:
  Hi everyone...
  Why isn't it happeing!!??
 
  Just the code from Net::SMTP docs
 
  __
 
  use strict;
  use warnings;
  use Net::SMTP;
 
  #these 3 lines bring the output mx.google.com
  # my $smtp = Net::SMTP-new('smtp.gmail.com') or die $!;
  # print $smtp-domain,\n;
  # $smtp-quit;
 
 
 
  #but for this...
  my $smtp = Net::SMTP-new('smtp.gmail.com') or die $!;
 
  $smtp-mail('som@gmail.com') or die $!;#it dies 
here. No

 errors.

 Does it die or does it hang?
 When I tried this, modified to connect to a bogus host, the 
program hung

 at this point.
 Editing to use a legitmate host it ran fine.

  And how are we going to know any mailhost's address???

 most programs/people ask the DNS system to return the mail host 
for any

 given domain.

  Its irritating when you fail on the first step.

 Yes it's irritating. What is your  objective?  To learn about 
SMTP and

 Perl or to
 just send some mail?

 If just send some mail consider using Mail::Sender or 
Mail::SendEasy.


 --
Michael Rasmussen, Portland Oregon
  Other Adventures: http://www.jamhome.us/ or
http://westy.saunter.us/
 Fortune Cookie Fortune du courrier:
  Linux is not user-friendly.
 It _is_ user-friendly.  It is not ignorant-friendly and 
idiot-friendly.

~ Seen somewhere on the net




 --
 Love,
  Somu,
 http://lose.yourself.mcommunity.biz
 http://fidel.castro.peperonity.com



--
 Michael Rasmussen
   http://www.jamhome.us/
Be Appropriate  Follow Your Curiosity

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




Re: Seek string to time module

2012-04-24 Thread Michael Rasmussen

On 2012-04-24 07:22, Brent Clark wrote:

Hiya

Is there a module to parse time.

I.e. 00:01:20.

The idea was to convert a string, i.e. time, and then to see if the
time given is greater than a threshold, for example 1 hour.

Hope I make sense. If anyone could help, it would be appreciated.


It makes sense.  You're looking for Date::Calc... wait _time_

Time::Format?
Time::Tiny  has a from_string function that looks like what you're 
after.

Is that what you're looking for?

--
 Michael Rasmussen
   http://www.jamhome.us/
Be Appropriate  Follow Your Curiosity

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




Re: Net::SMTP

2012-04-23 Thread Michael Rasmussen
On Tue, Apr 24, 2012 at 01:54:15AM +0530, Somu wrote:
 Hi everyone...
 Why isn't it happeing!!??
 
 Just the code from Net::SMTP docs
 
 __
 
 use strict;
 use warnings;
 use Net::SMTP;
 
 #these 3 lines bring the output mx.google.com
 # my $smtp = Net::SMTP-new('smtp.gmail.com') or die $!;
 # print $smtp-domain,\n;
 # $smtp-quit;
 
 
 
 #but for this...
 my $smtp = Net::SMTP-new('smtp.gmail.com') or die $!;
 
 $smtp-mail('som@gmail.com') or die $!;#it dies here. No errors.

Does it die or does it hang?
When I tried this, modified to connect to a bogus host, the program hung at 
this point.
Editing to use a legitmate host it ran fine.

 And how are we going to know any mailhost's address???

most programs/people ask the DNS system to return the mail host for any given 
domain.

 Its irritating when you fail on the first step.

Yes it's irritating. What is your  objective?  To learn about SMTP and Perl or 
to 
just send some mail?

If just send some mail consider using Mail::Sender or Mail::SendEasy. 

-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
 Linux is not user-friendly.
It _is_ user-friendly.  It is not ignorant-friendly and idiot-friendly.
~ Seen somewhere on the net

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




Re: and subroutine

2012-04-17 Thread Michael Rasmussen
On Tue, Apr 17, 2012 at 02:30:59PM +0200, Manfred Lotz wrote:
  Could someone please expand on this as I seem to always have to do
  this. If I 'use strict' and 'use warnings' I get errors if I don't.
  
 
 One example is this:
 
 #! /usr/bin/perl
 
 use strict;
 use warnings;
 
 mysub;
 
 sub mysub {
   print Hi there\n;
 }
 
 If you run this you get an error:
 Bareword mysub not allowed while strict subs in use at ./testsub.pl
 line 6. Execution of ./testsub.pl aborted due to compilation errors.
 
Alternatively, and to my sensibilities cleaner:

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

sub mysub;  #  declares it, mysub no longer a bareword

mysub();#  does it, () not required for Perl parser, but are nice for 
maintainers

sub mysub { # defines it
  print Hi!  Nice to see you!\n;
}

-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Whatever destiny your relationship has, a tandem will get you there faster.

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




Re: and subroutine

2012-04-17 Thread Michael Rasmussen
And for what it's worth.
113. Call subroutines with parentheses but without a leading 

That's from Damian Conway's Perl Best Practices
A quick reference to the 256 guidelines is found at
http://refcards.com/docs/vromansj/perl-best-practices/refguide.pdf

And a bit of luck, the entire chapter on subroutines, including the many 
reasons 
to prefer () to  is online:
http://www.devshed.com/c/a/Perl/Subroutines-in-Perl/


-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
The difference betwee a million and a billion is the difference between 
a sip of wine and 30 seconds with your daughter, and a bottle of gin and a 
night with her.
~ XKCD http://xkcd.com/558/

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




Re: Regex again..

2012-04-14 Thread Michael Rasmussen
On Sat, Apr 14, 2012 at 07:05:54PM +0300, Shlomi Fish wrote:
 Hi Somu,
 
 On Sat, 14 Apr 2012 21:01:03 +0530
 Somu som@gmail.com wrote:
 
  OK. Can i ask WHY?
  Why can't it be done using regex. Isn't a html file just another long
  string with more, but similar special characters??
  
 
 first of all I should note that you appear to be replying to the wrong 
 messages
 which breaks the flow of the thread. Otherwise, please read the links which I
 gave you:

I did, he may or may not have but ...
They all saw to not do it without the WHY.  The closest is 
  http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
It's a solved problem being the WHY given. 

Well, that's not totally fair of me. 

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
Does start:
 You can't parse [X]HTML with regex. Because HTML can't be parsed by
 regex. Regex is not a tool that can be used to correctly parse HTML. 
   ...
 Regular expressions are a tool that is insufficiently sophisticated to
 understand the constructs employed by HTML.

Though the humor in the rest of the post mask that essential statement.

Somu, regex to HTML parsing is like:
  screwdriver to nail
  butter knife to screw
  mid sized car to coal transport
  bicycle to 3,000 km journey to be completed in 48 hours
  meat to a vegetarian
  hair brush to can of paint

To a greater or lessor degree you might try to use one for the purpose
but it's not the right tool for the job.  

-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
By being willing to be a bad artist, you have a chance to BE an artist, 
and perhaps over time, a very good one 
~ Julia Cameron

s/artist/what you want to be/

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




Re: Regex again..

2012-04-14 Thread Michael Rasmussen
I hate it when I post something and then find a bit of information I should 
have included.

http://stackoverflow.com/questions/701166/can-you-provide-some-examples-of-why-it-is-hard-to-parse-xml-and-html-with-a-reg

The poster lists four valid HTML constructs that regex are ill equiped to 
handle.
The commentors add more examples.

Somu, I believe this is what you've been asking for.



On Sat, Apr 14, 2012 at 09:44:59AM -0700, Michael Rasmussen wrote:
 On Sat, Apr 14, 2012 at 07:05:54PM +0300, Shlomi Fish wrote:
  Hi Somu,
  
  On Sat, 14 Apr 2012 21:01:03 +0530
  Somu som@gmail.com wrote:
  
   OK. Can i ask WHY?
   Why can't it be done using regex. Isn't a html file just another long
   string with more, but similar special characters??
   
  
  first of all I should note that you appear to be replying to the wrong 
  messages
  which breaks the flow of the thread. Otherwise, please read the links which 
  I
  gave you:
 
 I did, he may or may not have but ...
 They all saw to not do it without the WHY.  The closest is 
   http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
 It's a solved problem being the WHY given. 
 
 Well, that's not totally fair of me. 
 
 http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
 Does start:
  You can't parse [X]HTML with regex. Because HTML can't be parsed by
  regex. Regex is not a tool that can be used to correctly parse HTML. 
...
  Regular expressions are a tool that is insufficiently sophisticated to
  understand the constructs employed by HTML.
 
 Though the humor in the rest of the post mask that essential statement.
 
 Somu, regex to HTML parsing is like:
   screwdriver to nail
   butter knife to screw
   mid sized car to coal transport
   bicycle to 3,000 km journey to be completed in 48 hours
   meat to a vegetarian
   hair brush to can of paint
 
 To a greater or lessor degree you might try to use one for the purpose
 but it's not the right tool for the job.  
 
 -- 
 Michael Rasmussen, Portland Oregon  
   Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
 Fortune Cookie Fortune du courrier:
 By being willing to be a bad artist, you have a chance to BE an artist, 
 and perhaps over time, a very good one 
 ~ Julia Cameron
 
 s/artist/what you want to be/
 
 -- 
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/
 
 

-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
You're suddenly worried about how much is in your retirement account, 
but other people are worried about how much is on their dinner plate tonight.
~ Rick Steves on the economy March 2009

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




Re: How Can I find all kinds of methods a Object support?

2012-04-12 Thread Michael Rasmussen
On Thu, Apr 12, 2012 at 06:29:09PM +0800, Zapp wrote:
 I had try it, codes is here:

 #!/usr/local/bin/perl -w

 use Class::Inspector;
 use IO::File;

 my @methods = Class::Inspector-methods('IO::File', 'full', 'public');

 print @methods;

 but it Only print this: ARRAY(0xaa4bc8)
 Why?


The documentation for Class::Inspector says:
   methods $class, @options
   For a given class name, the methods static method will returns ALL the 
methods available to that class. This includes all
   methods available from every class up the class' @ISA tree.

Returns a reference to an array of the names of all the available 
 methods on success, or undef if the class name is invalid or
the class is not loaded.

So you need to assign the return of Class::Inspector-methods to a scalar
and later defererence the reference.
You could make these changes:

  my $methods = Class::Inspector-methods('IO::File', 'full', 'public');
  print @$methods;
  # consider print join $/, @$methods;

and you'll get a list of methods.



-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Frobyshnobskurov?, I asked them, looking pleading. I think I was asking
for drain cleaner but they cottoned on when I dabbed my finger on the
map.Frobyshnobskurov, it said, plain as life. Ah, said a warty one,
finally understanding, Frropbussplanshikoo-ROFF! Hungarian is like that.
~ Cross country bike tourist Leo Woodland

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




Re: Help parsing tab delimited files

2012-04-08 Thread Michael Rasmussen
On Sun, Apr 08, 2012 at 08:44:53PM -0700, Binish A.R wrote:
 replace     @array = split (/\t/, $_);  with
               @array = split;
 
I advise to not do that, because when you add more data - like
  Joe Bob \t  Briggs 

@array will have three elements. 

My output from your sample data and program is:
Joe 
 Doe 

Jane 
 Doe

Which looks to be what you want.

Tiago - if you want to find a specified value why are you splitting the lines 
up?

something like:

while(FILE) {
  print if m/text_you_want/;
}



  From: Tiago Hori tiago.h...@gmail.com
 To: beginners@perl.org 
 Sent: Monday, April 9, 2012 6:42 AM
 Subject: Help parsing tab delimited files
  
 Hi Guys,
 
 I know there are modules for parsing tab delimited files, but I am trying to 
 develop a script as a learning exercise to learn the better, so any help 
 would be appreciated.
 
 Let's say I have two columns and two rows:
 
 Joe \t Doe
 Jane \t Doe
 
 So here is what I got:
 
 #!usr/bin/perl
 
 use strict;
 
 my $name;
 my $lastname;
 my@array;
 
 open(FILE, , columns.txt);
 
 while (FILE)
 {
 
     @array = split (/\t/, $_);
     print $array[0]\n;
     print $array[1]\n;
 }
 
 
 
 close(FILE);
 
 
 So right now this prints Joe and Jane. It seems the split is putting a column 
 in the array. Is there any way that I could parse a row at a time, with each 
 element becoming a entry in the array? My goal is to be able to go through 
 each row at a time and find a specific value.
 
 Thanks,
 
 Tiago
 
 
 
 
 ---
 
 Education is not to be used to promote obscurantism. - Theodonius 
 Dobzhansky.
 
 Gracias a la vida que me ha dado tanto
 Me ha dado el sonido y el abecedario
 Con él, las palabras que pienso y declaro
 Madre, amigo, hermano
 Y luz alumbrando la ruta del alma del que estoy amando
 
 Gracias a la vida que me ha dado tanto
 Me ha dado la marcha de mis pies cansados
 Con ellos anduve ciudades y charcos
 Playas y desiertos, montañas y llanos
 Y la casa tuya, tu calle y tu patio
 
 Vioeta Parra - Gracias a la Vida 
 
 
 Tiago S. F. Hori
 PhD Candidate - Ocean Science Center-Memorial University of Newfoundland
 tiago.h...@gmail.com
-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du jour:
The good thing about mistakes ~ they're better than regrets.
~ http://someoneoncetoldme.com/gallery/05112007

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