Re: ActiveState unauthorized license claims?

2019-05-31 Thread Michael Putch
On Fri, May 31, 2019 at 12:44 PM  wrote:

> > I would suggest posting this to the Perl 5 Porters list; it’s probably
> > the best venue to get an answer to your question.
> >
> > https://lists.perl.org/list/perl5-porters.html
>
> Thanks for the hint although the description "people interested in Perl5
> core development" and the currently discussed topics do not give me the
> impression that I am better off there.
>
> I'll try it there if there's no alternative.
>
> Mark
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
All ports (including Activestate's) originally go through the arena
controlled by group.   You are claiming that by restricting you in certain
ways  Activestate is interfering with rights you should have inherited from
the core licensing of Perl.  That is why it is a logical group to address
such issues -- those folks would be on top of such legal twists and know
whether Activestate has a leg to stand on or not.
However what IS relevant to this group is that although Activestate
used to be the  "only game in town" for native Windows that has not been
the case for many years.  If your application will run under something like
Strawberry Perl then you could dodge that bullet completely.


FW: Question about Beginning Perl by Simon Cozens

2016-09-01 Thread Walker, Michael E


From: Walker, Michael E
Sent: Thursday, September 01, 2016 12:47 PM
To: 'Aaron Wells'
Subject: RE: Question about Beginning Perl by Simon Cozens

Thank you all for sharing your perspective on this. I will compare both the 
first and second editions of Beginning Perl. Cozens’ writing style really 
resonates with me, because of the problem-solving approach he takes when 
introducing each Perl concept. For example, even though the book is outdated in 
some respects, I appreciated his examples on using the while loop to create a 
number guessing game, and as the book progressed, I saw something in there 
about computing a Taylor series. I believe I also saw a Fibonacci series. I 
also like how he describes file processing in depth. This contrasts with a lot 
of books I have seen where instead of problem-solving, it seems that simple 
examples are introduced, to demonstrate each language feature.

Mike

From: Aaron Wells [mailto:chacewe...@gmail.com]
Sent: Thursday, September 01, 2016 12:06 PM
To: Walker, Michael E
Subject: Re: Question about Beginning Perl by Simon Cozens


Edit: s/done/fine/

On Thu, Sep 1, 2016, 10:04 AM Aaron Wells 
mailto:chacewe...@gmail.com>> wrote:

Because Perl 5 has been committed to backward compatibility, I think beginning 
Perl is still a good reference for learning the Perl fundamentals. You'll learn 
the main concepts that make Perl Perl. And as with all things, it depends on 
what you're up to. If you're doing systems administration or automating things, 
sticking with that level is done. Application development is a different story 
though. "Modern Perl" will get you up to speed with the tools and techniques 
application developers are using to get application up and running faster with 
fewer bugs.

On Thu, Sep 1, 2016, 9:53 AM Walker, Michael E 
mailto:michael.e.walk...@boeing.com>> wrote:
Hi, even though Beginning Perl dates back to 2000, is it still relevant for 
learning today? I wondered, because when Googling, I saw posts recommending 
against its use, but yet it is still listed at 
books.perl.org<http://books.perl.org>. Please discuss, or point me to the 
archive on this list where this has been discussed. Thank you.


Question about Beginning Perl by Simon Cozens

2016-09-01 Thread Walker, Michael E
Hi, even though Beginning Perl dates back to 2000, is it still relevant for 
learning today? I wondered, because when Googling, I saw posts recommending 
against its use, but yet it is still listed at books.perl.org. Please discuss, 
or point me to the archive on this list where this has been discussed. Thank 
you.


RE: Start a New Thread for a New Question (WAS: This is one of the things ...)

2016-05-13 Thread Walker, Michael E
Thank you for letting me know.

-Original Message-
From: Shawn H Corey [mailto:shawnhco...@gmail.com] 
Sent: Friday, May 13, 2016 10:01 AM
To: beginners@perl.org
Subject: Re: Start a New Thread for a New Question (WAS: This is one of the 
things ...)

On Fri, 13 May 2016 13:20:15 +
"Walker, Michael E"  wrote:

> Hi,
> 
> What framework are you all using for database development? When 
> tracking this thread back to the original message, I thought, "Nice 
> syntax." I am overall new to Perl, but am learning it for ETL at work.
> 
> Thanks,
> Mike

Hi Mike,

FYI: To get as many responses as possible, you should start a new thread for a 
new question. If you tack onto a existing thread, some people will read just 
the subject and skip it as not interesting. Starting a new thread will get more 
people to read it. :)


--
Don't stop where the ink does.
Shawn

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





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




RE: This is one of the things ...

2016-05-13 Thread Walker, Michael E
Hi,

What framework are you all using for database development? When tracking this 
thread back to the original message, I thought, "Nice syntax." I am overall new 
to Perl, but am learning it for ETL at work.

Thanks,
Mike

-Original Message-
From: Shawn H Corey [mailto:shawnhco...@gmail.com] 
Sent: Friday, May 13, 2016 7:16 AM
To: beginners@perl.org
Subject: Re: This is one of the things ...

On Fri, 13 May 2016 00:11:57 -0400
Uri Guttman  wrote:

> i stick to using fat comma ( => ) only for key/value pairs. it has the 
> side effect of quoting a bareword to the left which makes those pairs 
> easier to read. so i never use it just for a comma though i have seen 
> it used like that. this is definitely a matter of taste and i know 
> mine is better than most! :)
> 
> as for q{} i stick to using it when there are quote chars in the 
> string. i haven't had trouble reading '' (vs "" vs q{}) as the null 
> string. pick a better font if you have trouble! :) also context (not 
> perl but code in general) should make it easier to know when a null 
> string is being used.

Another method is to use `constant` since it creates constant subs which perl 
replaces with the literal.

$ cat quotes.pl
#!/usr/bin/env perl

use constant {
qSPACE=> q{ },
qCOMMA=> q{,},
qQUESTION => q{?},
};

my $holders = join qCOMMA, (qQUESTION) x @cgi_params;

$ perl -MO=Deparse ./quotes.pl
use constant ({'qSPACE', ' ', 'qCOMMA', ',', 'qQUESTION', '?'}); my $holders = 
join(',', ('?') x @cgi_params); ./quotes.pl syntax OK


Notice in the join that qCOMMA and qQUESTION were replaced with the
literal.


-- 
Don't stop where the ink does.
Shawn

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





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




Re: Apologetic request for simple one-off script

2014-07-17 Thread Michael Lynch
how about using awk to print the last column, using number of columns
variable $NF:

awk '{print $NF}' file


Regards,
Mike


On Sun, Jul 13, 2014 at 4:43 PM, ESChamp  wrote:

> I apologize for having to ask this but my nearly-80-year-old brain just
> could not come up with a solution.
>
> I have a text file consisting of several space-separated fields:
>
> lastname firstname other other other ... emailaddress
>
> I wish to write a new file that contains only the emailaddress field
> contents.
>
> There's no need to test the emailaddress field.
>
> I just need a quick and dirty solution as this will be used just one time.
>
> Thanks in advance.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Can't find perldoc in Cygwin

2013-11-17 Thread Michael Brader

Hi Juan, see below:

On 11/18/2013 10:45 AM, Juan Wei wrote:

Michael,


Please send questions to the list. I'm not a private support channel and 
you will likely find more help faster there.



I have the Cywin version of perl installed on a Windows 7 computer, and
it does not have a perldoc executable.

How can I get perldoc functionality?


Hmm, when I go here: http://cygwin.com/packages/

and enter 'perldoc' in the search box and hit the 'Go' button, it tells me 
that the Perl package contains the perldoc executable in /usr/bin


So I would guess that your problem is that you have an old, incomplete or 
broken Perl package in your Cygwin install (solution: refresh the package), 
or that someone has installed it from source (solution: ask that person to 
install perldoc)


My advice is to try and fix that. If you have problems, you should ask on a 
Cygwin list: http://cygwin.com/lists.html


While you are waiting to resolve that issue, the perldoc pages are online 
at http://perldoc.perl.org/


Cheers,
Michael

--
Michael BraderSenior Software Engineer and Perl Person
There's no such thing as a DevOps team   Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au


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




Re: Reading a sequence data from a file

2013-11-12 Thread Michael Brader

Hey Femi,

Instructions and example code for doing all the things you want can be 
found in the standard Perl manual. You should be able to find it by opening 
a terminal window and using the perldoc command:


perldoc -f open
perldoc -f chdir
perldoc -q path

This is best, because the documentation you find will match your version of 
Perl.


Alternatively, you can see the same things on the web (by default for the 
latest stable version) at:


http://perldoc.perl.org/functions/open.html
http://perldoc.perl.org/functions/chdir.html
http://perldoc.perl.org/search.html?q=path

Read those, and try and write some code that solves your problem. If you 
have further trouble, feel free to email the list including the code you 
have tried and I or others here will be more than happy to assist.


Good luck,
Michael


On 11/13/2013 07:45 AM, Alaba, Oluwafemi (IITA) wrote:

Dear Michael,
Thanks for  your kind explanation. I understood it pretty well. I feel 
very fortunate to have you respond to my post.


I just wanna know if i must save that file ("NM021964fragment.pep") in a 
particular location in my OS X to run my scripts properly. It is not yet 
running.


Could you please write the lines of code exactly how I should run it? And 
would like to hear further instructions and recommendations.


Kind regards,
Femi

On Nov 12, 2013, at 1:08 AM, Michael Brader <mailto:mbra...@internode.com.au>> wrote:


Nathan has found your problem, but see below for more suggestions on 
your code:


On 11/12/2013 02:15 AM, Alaba, Oluwafemi (IITA) wrote:

*Dear ALL,*

I created a file named NM021964fragment.pep (using text editor) but I 
could not read that particular file.


*Here is the script I used:*

#!/usr/bin/perl -w


Remove the ' -w' above and add the following two lines to get extra 
error checking that will lead you towards better Perl programming habits


#!/usr/bin/perl

use strict;
use warnings;


#Reading protein sequence from a file

The filename of the file containing the protein sequence data
$proteinfilename = "NM021964fragment.pep";

#First we have to 'open' the file and associate it a 'filehandle' with 
it. We choose the filehandle

#PROTEINFILE for readability.

open(PROTEINFILE, $proteinfilename);


PROTEINFILE is known as a 'bareword filehandle' and it has some 
limitations. Better to use a filehandle variable. The '<' indicates that 
you are opening the file for reading. It is the default but using it 
tells someone reading your code what your intentions are. You should 
also check to see whether the open succeeded:


open my $PROTEINFILE, '<', $proteinfilename
or die "Failed to open protein file $proteinfilename. Reason: $!";



#now we do the actual reading of the protein sequence data from the 
file by using angle bracket < and >

$protein = ;


This will read the first line of the file including the trailing 
newline. If that is what you want, fine. The 'strict' line you inserted 
above means that you will have to declare variables on their first use. 
To remove the trailing newline use chomp:


my $protein = <$PROTEINFILE>;
chomp $protein;

If what you wanted is to read all the lines of the file, it is customary 
to use a while loop:


while ( my $protein = <$PROTEINFILE> ) {
chomp $protein;
# do something with $protein
}



close PROTEINFILE;


You should always check the return value of system calls such as close. 
It's unlikely after reading but a big problem after writing:


close $PROTEINFILE
or warn "Problem closing protein file $proteinfilename. Reason: $!";

Cheers,
Michael
--
Michael BraderSenior Software Engineer and Perl Person
There's no such thing as a DevOps team   Technology/Softdev/DevOps
Internodehttp://internode.on.net/   mbra...@internode.com.au
iiNethttp://iinet.net.au/  m.bra...@staff.iinet.net.au




--
Michael BraderSenior Software Engineer and Perl Person
There's no such thing as a DevOps team   Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au



Re: Reading a sequence data from a file

2013-11-11 Thread Michael Brader

Nathan has found your problem, but see below for more suggestions on your code:

On 11/12/2013 02:15 AM, Alaba, Oluwafemi (IITA) wrote:

*Dear ALL,*

I created a file named NM021964fragment.pep (using text editor) but I 
could not read that particular file.


*Here is the script I used:*

#!/usr/bin/perl -w


Remove the ' -w' above and add the following two lines to get extra error 
checking that will lead you towards better Perl programming habits


#!/usr/bin/perl

use strict;
use warnings;


#Reading protein sequence from a file

The filename of the file containing the protein sequence data
$proteinfilename = "NM021964fragment.pep";

#First we have to 'open' the file and associate it a 'filehandle' with 
it. We choose the filehandle

#PROTEINFILE for readability.

open(PROTEINFILE, $proteinfilename);


PROTEINFILE is known as a 'bareword filehandle' and it has some 
limitations. Better to use a filehandle variable. The '<' indicates that 
you are opening the file for reading. It is the default but using it tells 
someone reading your code what your intentions are. You should also check 
to see whether the open succeeded:


open my $PROTEINFILE, '<', $proteinfilename
or die "Failed to open protein file $proteinfilename. Reason: $!";



#now we do the actual reading of the protein sequence data from the file 
by using angle bracket < and >

$protein = ;


This will read the first line of the file including the trailing newline. 
If that is what you want, fine. The 'strict' line you inserted above means 
that you will have to declare variables on their first use. To remove the 
trailing newline use chomp:


my $protein = <$PROTEINFILE>;
chomp $protein;

If what you wanted is to read all the lines of the file, it is customary to 
use a while loop:


while ( my $protein = <$PROTEINFILE> ) {
chomp $protein;
# do something with $protein
}



close PROTEINFILE;


You should always check the return value of system calls such as close. 
It's unlikely after reading but a big problem after writing:


close $PROTEINFILE
or warn "Problem closing protein file $proteinfilename. Reason: $!";

Cheers,
Michael

--
Michael BraderSenior Software Engineer and Perl Person
There's no such thing as a DevOps team   Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au



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: Dealing with apache timeout in Perl

2013-09-04 Thread Michael Brader
If you don't have control of the web server you're going to have to get 
creative. Instead of returning the zip file from the page that processes 
the request, you could:


* ok - Fork a process to build the zip and place it in a location specific 
to the user or their session then return a page with a link to that 
location and a warning that the link may not work for a few minutes


* better - If you're comfortable with javascript (or meta-refresh at a 
pinch), you could fork the process, then return a page that tells the user 
that their request is in progress, then periodically refresh the results 
page until the zip is available.


This isn't really a Perl question, so if you need further help, you might 
want to ask it in a forum devoted to web development.


Cheers,
Michael


On 09/05/2013 01:25 PM, Chankey Pathak wrote:

Sorry I can't do that. Isn't there any other way?


On Wed, Sep 4, 2013 at 9:48 PM, jbiskofski <mailto:jbiskof...@gmail.com>> wrote:


You need to fix this in Apache not in your web-app. The setting is
called TimeOut in your httpd.conf - this is the number of seconds
Apache will wait before sending a timeout error and ending the request.

- Jose from Mexico.


On Wed, Sep 4, 2013 at 4:49 AM, Chankey Pathak mailto:chankey...@gmail.com>> wrote:

In my web-app there is a HTML screen which provides the facility
to select and download documents. If user selects some documents
(using checkbox) and submits the form then then all of his
selected documents gets downloaded in form of a zip file. What I
do is that I take user's selected documents and then use
Archive::Zip to create Zip file. It works fine.

But if the user had selected a lot of documents then the
create_zip subroutine takes a lot of time, and if it takes more
than 4 minutes (240 seconds) then apache timeout occurs causing
the 503 error, but in the backend the subroutine keeps doing the
job, but due to the timeout I can't send the created zip file to
user's browser.

I'm confused how to solve this problem. *How to keep the
connection alive unless the subroutine finishes its job?*

PS: Web-app is built using CGI.pm and Perl 5.8.5.


-- 
Regards,

Chankey Pathak <http://www.technostall.com>





--
Regards,
Chankey Pathak <http://www.linuxstall.com>


--
Michael BraderSenior Software Engineer and Perl Person
Our World Wide Web has a World Wide Network  Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au



Re: Filtering Characters

2013-09-03 Thread Michael Rasmussen
On Wed, Sep 04, 2013 at 02:31:30AM +0100, Rob Dixon wrote:
> Matt  wrote:
> >I have this:
> >
> >while () {
> >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() {
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: Print to several logs

2013-08-27 Thread Michael Brader
There are some good answers here so far, but I'd like to recommend a 
logging module like Log::Log4perl. If your script is more than a run-once 
throwaway, proper logging will almost certainly be of benefit.


Metacpan: https://metacpan.org/module/Log::Log4perl
FAQ: 
http://log4perl.sourceforge.net/releases/Log-Log4perl/docs/html/Log/Log4perl/FAQ.html

Tutorial: http://www.perl.com/pub/2002/09/11/log4perl.html

To log to two files:

#!/usr/bin/perl

use strict;
use warnings;

use Log::Log4perl qw(get_logger);

# Normally this would be in a separate file
my $log4perl_cfg = <<'EOCFG';
# Two appenders in our logger tmplog1 & tmplog2
log4perl.logger = DEBUG, tmplog1, tmplog2

log4perl.appender.tmplog1 = Log::Log4perl::Appender::File
log4perl.appender.tmplog1.filename = /var/tmp/one.log
log4perl.appender.tmplog1.layout   = PatternLayout
log4perl.appender.tmplog1.layout.ConversionPattern = %d> %m%n

log4perl.appender.tmplog2 = Log::Log4perl::Appender::File
log4perl.appender.tmplog2.filename = /var/tmp/two.log
log4perl.appender.tmplog2.layout   = PatternLayout
log4perl.appender.tmplog2.layout.ConversionPattern = %d> %m%n
EOCFG

Log::Log4perl->init( \$log4perl_cfg );
my $logger = get_logger();
my $rsync = 'rsync';

$logger->debug('About to rsync');
...;
$logger->info("kdkdkdkd Output from: $rsync cmdflgs");
exit 0;

Using Log4perl allows you to change how you log very easily, with appenders 
for output to files, the screen, databases etc. all available. The 
configuration format is somewhat verbose, so I generally use the Template 
Toolkit to generate it for me. The example below solves your same problem, 
but for N files instead of two:


#!/usr/bin/perl

use strict;
use warnings;

use Log::Log4perl qw(get_logger);
use Template;

my $logging_cfg_template = <<'EOCFG';
[% BLOCK appenders -%]
  [% FOR section IN sections %][% section.log_appender_name %][% ", " 
UNLESS loop.last %][% END %]

[%- END %]
[% BLOCK appender_sections %]
  [% FOR section IN sections %]
log4perl.appender.[% section.log_appender_name %] = 
Log::Log4perl::Appender::File
log4perl.appender.[% section.log_appender_name %].filename = [% 
section.log_file_name %]

log4perl.appender.[% section.log_appender_name %].layout = PatternLayout
log4perl.appender.[% section.log_appender_name %].layout.ConversionPattern 
= %d> %m%n

  [% END %]
[% END %]
log4perl.logger = DEBUG, [% PROCESS appenders %]
[% PROCESS appender_sections %]
EOCFG

my $template = {
sections => [
{ log_appender_name => 'tmplog1', log_file_name => 
'/var/log/one.log', },
{ log_appender_name => 'tmplog2', log_file_name => 
'/var/log/two.log', },
{ log_appender_name => 'tmplog3', log_file_name => 
'/var/log/three.log', },

],
};

my $tt = Template->new();

my $log4perl_cfg;
$tt->process( \$logging_cfg_template, $template, \$log4perl_cfg ) || die 
'Template error: ' . $tt->error();


# Comment or remove this line once you are happy with the generated config
print "CONFIG: $log4perl_cfg\n";

Log::Log4perl->init( \$log4perl_cfg );
my $logger = get_logger('main');
my $rsync  = 'rsync';

$logger->info("kdkdkdkd Output from: $rsync cmdflgs");

Cheers,
Michael


On 08/28/2013 06:44 AM, Harry Putnam wrote:

I happen to be scripting something that needs to have two logs written
to and was sort of taken by how awkward this construction looked:

(Simplified for discussion, from a longer script)

   my $rsync = 'rsync';
   my $tmplog = 'one.log';
   my $tmplog2 = 'two.log';
   open(LOG,">>$tmplog")or die "Can't open $tmplog : $!";
   open(LOG2,">>$tmplog2")or die "Can't open $tmplog2: $!";
   print LOG  "kdkdkdkd Output from:\n$rsync cmdflgs";
   print LOG2 "kdkdkdkd Output from:\n$rsync cmdflgs"
   close(LOG);
   close(LOG2);

Is there some smooth way to write to more than one log?

I tried just adding the second one to the first print like this:

  print LOG LOG2 "[...]";

   But that fails with an error:

   String found where operator expected at ./t1.pl line 109, near "LOG2
   "kdkdkdkd Output from:\n$rsync cmdflgs""

 (Do you need to predeclare LOG2?)

   syntax error at ./t1.pl line 109, near "LOG2 "kdkdkdkd Output
   from:\n$rsync cmdflgs""

   Execution of ./t1.pl aborted due to compilation errors.




--
Michael BraderSenior Software Engineer and Perl Person
Our World Wide Web has a World Wide Network  Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au


--
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: 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 
> wrote:
> 
> > 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: 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: Convert any date format to ISO

2013-07-27 Thread Michael Brader


On 07/26/2013 06:10 AM, Charles DeRykus wrote:



On Wed, Jul 24, 2013 at 10:56 PM, Michael Brader 
mailto:mbra...@internode.com.au>> wrote:


[...]
There are at least 2 modules that can definitely do the job for you,
Date::Manip::Date and DateTime (with DateTime::Format::Natural). I
usually use the latter, but since you want the former:

Have a look at the documentation for Date::Manip::Date and look for
parse_format and printf



Date::Manip and friends are wonderfully versatile but with even in this 
simple case, it does start to get a bit twisty with special parse and 
output methods:


[...]


Agreed, that's why I tend to stick with DateTime these days.

Cheers,
Michael

--
Michael BraderSenior Software Engineer and Perl Person
Our World Wide Web has a World Wide Network  Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au



Re: Convert any date format to ISO

2013-07-24 Thread Michael Brader


On 07/25/2013 03:26 PM, Jim Gibson wrote:

You don't need a module to recognize a date in the form DD-MM- and change 
it into the form -MM-DD (untested):

if( $date =~ /^(\d\d)-(\d\d)-(\d\d\d\d)$/ ) {
   $date = "$3-$2-$1";
}else{
 # try other conversions
}


Jim's right, but be aware that when you roll your own date code, you are 
taking all the validation work upon yourself. If you can trust your input, 
that's probably fine, but if you are dealing with user input or input from 
an untrusted source, you probably want to let CPAN do the work for you.


For example, the code above will happily turn '99-99-2013' into '2013-99-99'.

Cheers,
Michael

--
Michael BraderSenior Software Engineer and Perl Person
Our World Wide Web has a World Wide Network  Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au


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




Re: Convert any date format to ISO

2013-07-24 Thread Michael Brader


On 07/25/2013 10:14 AM, mimic...@gmail.com wrote:
I was trying to use Date::Simple to convert date from DD-MM- to ISO 
standard -MM-DD,  but it produced error below because it returned 
undef when the date passed is not ISO standard.


Yeah on quick scan of the perldoc it looks like Date::Simple doesn't offer 
much in the way of parsing.



[...]

Most of the date modules on CPAN cannot do the job for me. I spent time 
reading documentations but as it now stands, I have to do  this myself.




There are at least 2 modules that can definitely do the job for you, 
Date::Manip::Date and DateTime (with DateTime::Format::Natural). I usually 
use the latter, but since you want the former:


Have a look at the documentation for Date::Manip::Date and look for 
parse_format and printf


If you are still stuck, don't hesitate to show your attempt and ask for 
more help.


Cheers,
Michael

--
Michael BraderSenior Software Engineer and Perl Person
Our World Wide Web has a World Wide Network  Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au



Re: Parsing Data

2013-07-22 Thread Michael Brader


On 07/23/2013 11:08 AM, Omega -1911 wrote:
Rob - Thanks for the tip. I am not familiar with the module (XML::XPath) 
but tried to play with the code a little more to also retain the URL as 
well but was not successful. What would I need to modify or add to do 
this? After a 14 hour work day, I would love to wrap this up so I can 
transfer my contacts to my new address book. Thanks again to all. 


  my $url = $item->findvalue('a[@class="lnk-store-item"]/@href');

See an XPath reference for why.

And go to bed!

Cheers,
Michael

--
Michael BraderSenior Software Engineer and Perl Person
Our World Wide Web has a World Wide Network  Technology/Softdev/DevOps
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au


--
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 ;

# 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: 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  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  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: 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: 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, as all current procedures I have found have failed for me.

2013-05-24 Thread Michael Goldsbie
Ah yes, I finally found the problems:

http://padre.perlide.org/trac/ticket/1438
http://padre.perlide.org/trac/ticket/1474
http://padre.perlide.org/trac/ticket/1457


So all this time, the source of my frustration has been the result of bugs.
 Well, I do feel better knowing this rather than it being a problem on my
end (i.e. me doing something wrong), which is what I had assumed up until
now.

Is there a way I can create an account on that site so I can help track and
verify bugs?  I used to work in software quality assurance, so I know quite
a bit about using a bugtracker.


On Fri, May 24, 2013 at 4:58 PM, Michael Goldsbie <
michael.golds...@alum.utoronto.ca> wrote:

> There is, yes, and thank you for telling me about it.  However, still,
> nothing happens when I choose Run Script.  I am guessing some components
> are not correctly installed or something.
>
>
> On Fri, May 24, 2013 at 4:50 PM, Robert Wohlfarth 
> wrote:
>
>> On Fri, May 24, 2013 at 3:25 PM, Michael Goldsbie <
>> michael.golds...@alum.utoronto.ca> wrote:
>>
>>> *In Padre, I have typed the simple script
>>> **
>>> print "Hello world\n";
>>>
>>> and yet when I choose Run > Run Script, nothing happens.  No new window,
>>> no indication that it's compiled or failed...nothing.  In addition, when I
>>> choose Tools > Module Tools > Open CPAN Config File, I get the error
>>> "Failed to find your CPAN configuration".
>>> *
>>>
>>
>> Isn't there an "Output" window or something at the bottom of Padre? It's
>> been a while since I've used it. I seem to recall that standard output gets
>> sent there.
>>
>> --
>> Robert Wohlfarth
>>
>
>


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

2013-05-24 Thread Michael Goldsbie
There is, yes, and thank you for telling me about it.  However, still,
nothing happens when I choose Run Script.  I am guessing some components
are not correctly installed or something.


On Fri, May 24, 2013 at 4:50 PM, Robert Wohlfarth wrote:

> On Fri, May 24, 2013 at 3:25 PM, Michael Goldsbie <
> michael.golds...@alum.utoronto.ca> wrote:
>
>> *In Padre, I have typed the simple script
>> **
>> print "Hello world\n";
>>
>> and yet when I choose Run > Run Script, nothing happens.  No new window,
>> no indication that it's compiled or failed...nothing.  In addition, when I
>> choose Tools > Module Tools > Open CPAN Config File, I get the error
>> "Failed to find your CPAN configuration".
>> *
>>
>
> Isn't there an "Output" window or something at the bottom of Padre? It's
> been a while since I've used it. I seem to recall that standard output gets
> sent there.
>
> --
> Robert Wohlfarth
>


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

2013-05-24 Thread Michael Goldsbie
*NOTE: To skip directly to the problem itself, skip to the bolded text
below. However, I thought I would give some background context first.*


Hi,

My name is Michael, and I am trying to get into Perl.  While I have Ubuntu
Linux installed on my computer, my default environment is Windows 7, and
ideally I would like to do everything on this OS.  I would also ideally
prefer to use a single IDE than a text editor + compiler.  Apparently,
Padre is typically the IDE that everyone uses.

So I started here:

http://learn.perl.org/installing/windows.html

However, instead of JUST installing Padre, I installed DWIM Perl, which
includes Padre, Strawberry Perl, and many other goodies.

http://padre.perlide.org/download.html

So after downloading and installing it, what's the next step?  Is a reboot
of my computer necessary (especially since it doesn't explicitly tell me to
do so)?  Do I use the command "cpan App::cpanminus" as per the first link
above?  Do I go to the following page and run the following script in the
DOS window?

http://padre.perlide.org/howto.html

C:\Dwimperl\perl\bin\perl.exe -MCPAN -e "CPAN->upgrade('/^Padre/')"


The problem is that when I run that script, many of those tests fail.
The "cpan
App::cpanminus" command does not work either, as I receive the following
error:

*Can't locate App/Cpan.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/msys
/usr/*
*lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/msys
/usr/lib/perl5/site_perl/5.8*
*.8 /usr/lib/perl5/site_perl .) at /c/Dwimperl/perl/bin/cpan line 5.*
*BEGIN failed--compilation aborted at /c/Dwimperl/perl/bin/cpan line 5.*


*
However, I'm not sure if these extra commands in the DOS window are
necessary, so let's just go right to Padre.


*In Padre, I have typed the simple script
**
print "Hello world\n";

and yet when I choose Run > Run Script, nothing happens.  No new window, no
indication that it's compiled or failed...nothing.  In addition, when I
choose Tools > Module Tools > Open CPAN Config File, I get the error
"Failed to find your CPAN configuration".

I'm at my wit's end trying to figure out how to make this work.  Any help
would be much appreciated.


Thank you very much,

Michael*


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: obfuscating code

2013-02-12 Thread Michael Smith
I don't know if he was speaking of making the code you can see hard to 
understand (like some sigs I've seen) or keeping others, online perhaps, from 
the seeing the code (like object code). You can of course "see" object code but 
you would have to be able to read machine code, in hex, and most don't bother.

Two very different things.





 From: Rajeev Prasad 
To: perl list  
Sent: Tuesday, February 12, 2013 11:01 AM
Subject: obfuscating code
 
freinds,

what is the advice just for obfuscating code? platform is solaris.

ty.

Re: getting perl to open pl file extension in XP

2013-02-02 Thread Michael Smith
Sorry Tim. I thought after I wrote that perhaps I should have been very 
specific even though that would've also made it very long.

When I said, "I tried all the regular ways to change file extensions in XP." 
what you suggested is exactly what I tried -- many times. I even redid it 
again, just now, Exactly as you wrote it, in case perhaps pushing one button 
out of order could cause a failure. The same thing happens. The "Open with" 
window disappears and the program that opens the pl file extension remains the 
same.

The only thing left that I can figure to try is: The delete button in that 
"Open with" window is grayed out (why I have no idea) so I though uninstall 
perl, delete .pl in the registry and reinstall perl.

If that does nothing getting a new OS is looking better and better :)

I wonder if Perl not being in the "Program Files" folder has anything to do 
with it not being on the list in the "Open with" window so that it is necessary 
to "browse." That list is somewhere in the registry, if I could find it and add 
perl to it???

Although some of them were so far over my head as to be non-readable Everyone 
Thanks you very much for all the responses. 

ms




____
 From: timothy adigun <2teezp...@gmail.com>
To: Michael Smith  
Cc: "beginners@perl.org"  
Sent: Saturday, February 2, 2013 11:40 AM
Subject: Re: getting perl to open pl file extension in XP
 
Hi

On Sat, Feb 2, 2013 at 5:29 PM, Michael Smith  wrote:

> I know get a new OS :)
>
> First I installed strawberry perl but it has no GUItest and I couldn't get
> guitest to install. Then I deleted strawberry and I installed
> padre-on-strawberry because it says it already contains GUItest and now I
> can't get anything but notepad to open the pl files. I have to type
> perl.exe test.pl every time and I'm just way to lazy for that.
>
> I tried all the regular ways to change file extensions in XP. Perl.exe
> isn't listed in the window, I hit the "browse" button go though the files
> to perl.exe and hit open or double click and that window goes away but 'pl
> files still open with notepad. I tried deleting the .pl in the registry and
> entering pl as "new" but that didn't work either.
>
>     I recently installed Strawberry Perl for one colleagues at work who
what to learn Perl Programming. He also had this same problem. The
following was what I did on his system using Win 7 OS:

Right click on the perl program you what to run,
then click on *open with*, then click on *Choose default Program*,
then click on "*Browse*" Button, locate the "Perl Command Line Interpreter"
in the bin folder for your perl installation in your system.
Select it, and check the button "*Always use selected program to open this
kind of file*".
Click on the *OK* button.
You should be able to run your perl program from your CLI. If your PATH is
correctly set.

Hope this helps.


> Any help greatly appreciated.
>
> ms
>



-- 
Tim

getting perl to open pl file extension in XP

2013-02-02 Thread Michael Smith
I know get a new OS :)

First I installed strawberry perl but it has no GUItest and I couldn't get 
guitest to install. Then I deleted strawberry and I installed 
padre-on-strawberry because it says it already contains GUItest and now I can't 
get anything but notepad to open the pl files. I have to type perl.exe test.pl 
every time and I'm just way to lazy for that.

I tried all the regular ways to change file extensions in XP. Perl.exe isn't 
listed in the window, I hit the "browse" button go though the files to perl.exe 
and hit open or double click and that window goes away but 'pl files still open 
with notepad. I tried deleting the .pl in the registry and entering pl as "new" 
but that didn't work either.

Any help greatly appreciated.

ms


Re: jsFiddle

2013-01-15 Thread Michael Dabydeen
Have you had a look at http://codepad.org? I think it does something
similar.

On Tue, Jan 15, 2013 at 2:35 PM, Bill Stephenson wrote:

> Check out this web app:
>
> http://jsfiddle.net/
>
> (Google "jsfiddle.net example" for examples of use)
>
> It would be nice to have something like that for fiddling with perl.
>
> I haven't really thought it through, but it might not take much to create
> something simple for personal use.
>
> --
>
> Bill Stephenson
>
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
Regards,

*Michael Dabydeen *
*
*
*Telephone (M)*: 647-389-2286
*Web:* http://about.me/mikedabydeen

---
This transmission (including any attachments) may contain confidential
information, privileged material (including material protected by the
solicitor-client or other applicable privileges), or constitute non-public
information. Any use of this information by anyone other than the intended
recipient is prohibited. If you have received this transmission in error,
please immediately reply to the sender and delete this information from
your system. Use, dissemination, distribution, or reproduction of this
transmission by unintended recipients is not authorized and may be unlawful.


Re: What is the difference between () and [] syntax for array?

2013-01-07 Thread Michael Brader
On 01/08/2013 12:03 PM, Neo Anderson wrote:
> I think there are two ways to declare an array:
> my @a1 = (1, 2, 3);my @a2 = [1, 2, 3];
> What is the difference? 

The first declares an array with three elements 1, 2 and 3.

The second declares an array with 1 element, a (scalar) reference to a 3
element list.

See 'perldoc perldata' and 'perldoc perlref' for details of the syntax, and
maybe 'perldoc perldsc' (Data Structures Cookbook) for some worked examples
of complicated structures.

Run the following code to illustrate the difference:

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper qw/ Dumper /;;

my @a1 = ( 1, 2, 3 );
print '@a1: ' . Dumper(\@a1);
my @a2 = [ 1, 2, 3 ];
print '@a2: ' . Dumper(\@a2);

Cheers,
Michael

-- 
Michael BraderSenior Software Engineer and Perl Person
  Technology/Softdev/M&E Small Change Team
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au


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




Re: regular expression help

2012-09-20 Thread Michael Brader


On 09/20/2012 04:39 PM, Irfan Sayed wrote:

got it myself :)
thanks a lot
  $line_to_add =~ m/([a-zA-Z]+\.csproj)/;



Hi Irfan,

Your solution will only match files that consist of ASCII alphabetic 
characters followed by '.csproj'. It will also match these:


* 'c:\p4\car\abc\foo.csproj\file.txt'
* 'c:\p4\car\abc\123xyx.csproj'
* 'c:\p4\car\abc\xyz.csprojabc'

Octavian's solution is much more general. Run this program to see why:

#!/usr/bin/perl

use strict;
use warnings;

my @paths = (
'c:\p4\car\abc\xyz.csproj',
'c:\p4\car\abc\foo.csproj\file.txt',
'c:\p4\car\abc\123xyx.csproj',
'c:\p4\car\abc\xyz.csprojabc',
);

foreach my $path ( @paths ) {
my ($irfan) = $path =~ m/([a-zA-Z]+\.csproj)/;
$irfan ||= 'no match';
my ($octavian) = $path =~ /([^\\]+)$/;
$octavian ||= 'no match';
print <<"EOINFO";
Path: $path
Irfan: $irfan
Octavian: $octavian

EOINFO
}
__END__

Path: c:\p4\car\abc\xyz.csproj
Irfan: xyz.csproj
Octavian: xyz.csproj

Path: c:\p4\car\abc\foo.csproj\file.txt
Irfan: foo.csproj
Octavian: file.txt

Path: c:\p4\car\abc\123xyx.csproj
Irfan: xyx.csproj
Octavian: 123xyx.csproj

Path: c:\p4\car\abc\xyz.csprojabc
Irfan: xyz.csproj
Octavian: xyz.csprojabc

A more idiomatic way to do this is to use the File::Spec module. Inspect 
the output of this program for inspiration:


#!/usr/bin/perl

use strict;
use warnings;

use File::Spec; # for splitpath

my $path = 'c:\p4\car\abc\xyz.csproj';

my ( $volume, $directories, $file) = File::Spec->splitpath( $path );

print <<"EOINFO";
Volume: $volume
Directories: $directories
File: $file
EOINFO

exit 0;
__END__

Cheers,
Michael


--
Michael BraderSenior Software Engineer and Perl Person
  Technology/Softdev/M&E Small Change Team
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au


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




Re: How to set ">" as record separator in a Perl one liner?

2012-07-16 Thread Michael Brader

On 07/16/2012 04:05 PM, De-Jian Zhao wrote:

Hi,

I want to change the record separator in a Perl one liner with ">" as the 
separator. However, I tried without success.


The perlrun document 
(http://perldoc.perl.org/perlrun.html#Command-Switches) says that*
"***-0*[/octal/hexadecimal/] * specifies the input record separator (|$/| 
) as an octal or hexadecimal number. *"
*When I tried to get the octal/hexadecimal code of ">" with oct(">") and 
hex(">"), I got "0". I used this number and it did not work the way I 
wanted (perl -00 -ne 'print if //' test.seq ).




From 'perldoc -f oct'

...
oct Interprets EXPR as an octal string and returns the corresponding
value.
...
To go the other way (produce a
number in octal), use sprintf() or printf():

$perms = (stat("filename"))[2] & 0;
$oct_perms = sprintf "%lo", $perms;

So it is used for converting a string into an octal value. But we can go 
the other way with printf and ord:


perl -e 'printf "%lo\n", ord(q{>})'
76

Now perl will leave the input record separator on the string, but we can 
take that off with chop:


echo '>>' | perl -0076 -nE 'chop,say if /AAAA/'


TIMTOWTDI of course, and you could also do it like this:

echo '>>' | perl -nE 'for (split />/) { say if // }'


Cheers,
Michael


Do the functions (oct and hex) return the octal and hexadecimal value of 
the inputted character? The document on the web seems to give different 
answers.


http://perldoc.perl.org/index-functions-by-cat.html#Functions-for-SCALARs-or-strings 

hex <http://perldoc.perl.org/functions/hex.html> - convert a string to a 
hexadecimal number
oct <http://perldoc.perl.org/functions/oct.html> - convert a string to an 
octal number


http://perldoc.perl.org/functions/hex.html
*hex EXPR **hex* Interprets EXPR as a hex string and returns the 
corresponding value.


http://perldoc.perl.org/functions/oct.html
*oct EXPR **oct* Interprets EXPR as an octal string and returns the 
corresponding value.


I tested the functions. The first description is possibly wrong. If I am 
right, which functions could be used to get the octal and hexadecimal 
number of a string? How should the Perl one liner be written to change 
the record sepatator to ">"? Thanks for your attention.


Dejian




--
Michael BraderSenior Software Engineer and Perl Person
  Technology/Softdev/M&E Small Change Team
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au




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




Re: Something mojolicious

2012-07-05 Thread Michael Greb
On Thu, Jul 5, 2012 at 6:19 AM, lina  wrote:
> PORT STATESERVICE
> 3000/tcp filtered ppp

This should show state 'open'.  Do you have a firewall configured that
would be blocking this?  'iptables -L -vn' output will show this.

Mike

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




Re: How to create a user manual window

2012-06-12 Thread Michael Putch
  I hate when I do that.  :(This email contains my actual comments (see
below).

On Tue, Jun 12, 2012 at 9:50 AM, Bob McConnell  wrote:

> > From: Paul Johnson
> >
> > On Tue, Jun 12, 2012 at 07:11:57PM +0300, Shlomi Fish wrote:
> >
> > > OK. For Windows there is now http://dwimperl.com/ which is open-source
> > and is
> > > considered better than Activestate Perl.
> >
> > [citation needed]
>
> I don't know about DWIMPerl itself, but it claims to be based on
> Strawberry, which I do use. The biggest advantage Strawberry has over
> ActiveState is the direct use of CPAN and all available modules there. It
> is not limited to the adulterated and incomplete collection provided by
> ActiveState.
>
> Bob McConnell
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>
Not to drift too far[further] off-topic here, but I completely agree on
Strawberry Perl itself -- I have finally made the jump from Activestate and
am happy with it for all of the reasons Paul states (not to mention that it
includes a compatible-by-definition C compiler for building packages that
require it.
I confess I had not heard of dwimperl before. I am trying to stay
open-minded about it, but from what I see on its webpage it has a major
focus on Having "The" Packages You "Must" Have (especially given its
inclusion of Task::Kensho, which goes even further in that direction).
Granted many of them are powerful and desirable, but the direction with
respect to Strawberry Perl seems to be toward less flexibility rather than
more.


Re: How to create a user manual window

2012-06-12 Thread Michael Putch
On Tue, Jun 12, 2012 at 9:50 AM, Bob McConnell  wrote:

> > From: Paul Johnson
> >
> > On Tue, Jun 12, 2012 at 07:11:57PM +0300, Shlomi Fish wrote:
> >
> > > OK. For Windows there is now http://dwimperl.com/ which is open-source
> > and is
> > > considered better than Activestate Perl.
> >
> > [citation needed]
>
> I don't know about DWIMPerl itself, but it claims to be based on
> Strawberry, which I do use. The biggest advantage Strawberry has over
> ActiveState is the direct use of CPAN and all available modules there. It
> is not limited to the adulterated and incomplete collection provided by
> ActiveState.
>
> --
>
>
>


RE: Bareword and strict subs

2012-05-31 Thread Michael Brader
A bareword is an unquoted string appearing in Perl source. Depending on context 
it is treated as a sub call or a string (or a filehandle and a few other things 
I'd imagine).

Barewords that are not sub calls are generally not permitted under "use strict" 
(specifically "use strict 'subs'"), with exceptions such as inside a hash key 
or immediately preceding a fat comma '=>'.

In your case, you appear to have omitted the sigil $ before 'attrs' in your 
call to 'new'.

See 'perldoc perldata' for more info on barewords and 'perldoc strict' for more 
info on what "use strict 'subs' forbids and allows.

Cheers,
Michael

Michael Brader
Senior Software Engineer - Billing
Techops - Softdev
Internode http://www.internode.on.net/


From: Mark Haney [ma...@abemblem.com]
Sent: Friday, 1 June 2012 7:58 AM
To: beginners@perl.org
Subject: Bareword and strict subs

I'm getting this error in one of my packages (built by a previous coder):

> Bareword "%s" not allowed while "strict subs" in use

In this case the "%s" is attrs.  Here's the bit of code it's choking on:


sub insert_shift {
   my $self = shift;
   my $attrs = @_;

   my $m = $self->schema->resultset('Shifts')->new(attrs);
   $m->insert;
}

I've googled this error, but what I've found is not very informative.  I
have no idea what a Bareword is in the Perl context.  Can someone
explain what's going on?

--

Mark Haney
Software Developer/Consultant
AB Emblem
ma...@abemblem.com
Linux marius.homelinux 3.3.7-1.fc16.x86_64 GNU/Linux

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



--
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.

 


-- 
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: 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 Dixon"
>>> 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: Getopt::Long

2012-05-16 Thread Michael Brader
Hi,

Your problem is that Getopt::Long is consuming your -help as the argument to 
-abc before it can be recognised. You might be able to do something with the 
other Getopt::* modules, but the following piece of code will do what you want 
if you really need it:

use List::MoreUtils qw(any);
use Getopt::Long;

my $abc;
my $help;

if ( any { $_ eq '-help' } @ARGV ) {
$help = 1;
}

GetOptions (
"abc=s" => \$abc,
"help" => \$help
);

if ( $help ) { print "This is help message\n" ; exit ;}

if ($abc) { print "You have choosen \"abc\" as $abc" };

# ==

If you don't have List::MoreUtils installed and can't install it, replace the 
'if ( any...)' block with:

foreach my $arg (@ARGV) {
if ( $arg eq '-help' ) {
$help = 1;
last;
}
}

Cheers,
Michael

-- 
Michael Brader
Senior Software Engineer - Billing
Techops - Softdev
Internode http://www.internode.on.net/


From: Rajesh Saha [rajeshsaha...@gmail.com]
Sent: Wednesday, 16 May 2012 6:39 PM
To: beginners@perl.org
Subject: Getopt::Long

Hi,

In my program, I am using the module Getopt::Long

My intension is that if the user chooses "--help", the program should show
the help message without bothering whether other options has been used or
not.

My program (say, test.pl) :

use Getopt::Long
my $abc;
my $help;

Getoptions ( "abc=s" => \$abc,
   "help" => \$help
 );

if ($help) { print "This is help message\n" ; exit ;}

if ($abc) { print "You have choosen \"abc\" as $abc" };


If I run this:

1.test.pl -help
Output: This is help message

2. test.pl -abc ABC
Output : You have choosen abc as ABC

3. test.pl -abc -help
Output: You have choosen abc as -help

Out the above results 1 & 2 are fine, but 3 is not as I want. I understand
what's happening here [$abc is assigned as "-help"], but don't have idea
how to implement it properly so that in the 3rd it would print like " This
is help message" .

Can anybody help please ?


Thanks n regards
Rajesh Saha

--
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:

  DB<1> n   
 
main::(tpl:6):  my @file = ;

And after that just press  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: Can't find string terminator

2012-05-09 Thread Michael Brader
The error is telling you exactly what the problem is, your final terminator 
is missing (because you've quoted it). To save you all that backwhacking, 
consider using qq:


$ssh->cmd( qq{mysqldump -uroot -pnew-password -t -T/var/lib/mysql free 
ExData --fields-enclosed-by=" --fields-terminated-by=|} );


Read 'perldoc perlop' for more information on qq.

Depending on how Net::SSH::Perl handles the argument to cmd, you may still 
need to quote the double quote and pipe symbols:


$ssh->cmd( qq{mysqldump -uroot -pnew-password -t -T/var/lib/mysql free 
ExData --fields-enclosed-by='"' --fields-terminated-by='|'} );


Cheers,
Michael

On 05/10/2012 11:32 AM, Alvin Ramos wrote:

Have a simple perl script that will run a mysql dump, but I'm getting

Can't find string terminator '"' anywhere before EOF at ./ssh.pl line 5

My code, I assume the " is throwing it all off, but the / didn't help:

use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new("heaven.theflux.net");
 $ssh->login("root", "temp");
 $ssh->cmd("mysqldump -uroot -pnew-password -t -T/var/lib/mysql free
ExData --fields-enclosed-by=\"\ --fields-terminated-by=\|\");

Thank you for any and all assistance!

Regards,
Al



--
Michael Brader
Senior Software Engineer - Billing
Techops - Softdev
Internode http://www.internode.on.net/


--
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  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 = ;
my $line_count;
my $max_len = 0;
while() {
$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: 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-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  
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  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 

>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: 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
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: & 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: 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  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: 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  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: 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() {
  print if m/text_you_want/;
}



>  From: Tiago Hori 
> 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 ()
> {
> 
>     @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/




Re: Why do I get a warning?

2012-03-22 Thread Michael Putch

On 3/22/2012 3:47 PM, Manfred Lotz wrote:

Hi all,
If I run the following small test snippet

<--snip>
#! /usr/bin/perl

use strict;
use warnings;

use autodie;



open my $hdl, ">", "fileio1.txt";
print $hdl "a line\n";
close $hdl;

open HDL, ">", "fileio2.txt";
print HDL "a line\n";
close HDL;
<--snap>


I get the message:
Name "main::HDL" used only once: possible typo at ./fileio1.pl line 16.

Why? The same as with $hdl above I use HDL three times.



   You can't use "typeglob" style filehandles with autodie -- it only 
works with lexical filehandles (one reason that the latter are now 
preferred).   See the Bugs section of "perldoc autodie".


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




Testing for Missing Packages

2011-12-24 Thread Eric James Michael Ritz

Hello everyone.

Here is my question: What is the preferred way to test a system for
installed modules?  For example, I have a Perl program I would like to
distribute.  It depends on a number of modules from CPAN and I would
like an easy way to test for the existence of those modules.  I
suppose the user could always run the program and then install them
whenever he gets an error about the packages not being found, but it
feels like there should be a friendlier way to address that.

Is there a common way in Perl to say, “This program depends on these
packages and requires them to be installed before running?”  And if
so, is there a common, automated way to prompt the user to install any
of those missing packages?

Thanks in advanced and happy holidays everyone!

--
ejmr
南無妙法蓮華經


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




Re: whats the purpose of use Data::Dumper;

2011-06-01 Thread Michael Greb
On Wed, Jun 01, 2011 at 09:07:45AM -0700, eventual wrote:
> use Data::Dumper;
> 
> Hi,
> Can someone give me a few examples on the purpose of use Data::Dumper;
> I tried reading but I could not understand.
> Thanks

Data::Dumper is a useful modules for converting perl data structures into a
string for printing.  It can be used for debugging, understanding how
somebody else's code works, tranffering information, etc.  The full
docs for the module can be found at
<http://search.cpan.org/perldoc?Data::Dumper>.

Here's a simple example:
#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

use Data::Dumper;

my @foo = ( 'one', 'two', 'three' );
my %bar = ( 'redfish' => 'bluefish', 'onefish' => 'twofish' );

my $more_complex = [
{ foo => 'bar', 'baz' => 'biz' },
'two',
{ a => 'b', c => [ 'one', 'two', 'three' ] }
];

say Data::Dumper->Dump( [ \@foo, \%bar, $more_complex ],
[ 'foo', 'bar', 'more_complex' ] );

Produces this output:

$foo = [
 'one',
 'two',
 'three'
   ];
$bar = {
 'onefish' => 'twofish',
 'redfish' => 'bluefish'
   };
$more_complex = [
  {
'baz' => 'biz',
'foo' => 'bar'
  },
  'two',
  {
'c' => [
 'one',
 'two',
 'three'
   ],
'a' => 'b'
  }
];

--- END --

Hopefully this is useful.

Mike

-- 
Michael
mich...@thegrebs.com
M: +1-562-MIKEGRB

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




Re: Conversion program decimal to hex and oct using assertions

2011-05-30 Thread Michael Greb
On Tue, May 31, 2011 at 02:27:53PM +1000, Sayth Renshaw wrote:
> This there formula $oct_perm_str = sprintf "%o", $perms;
> However it is not working for me. I have used my $oct = sprintf "%0", $number;

You want '%o', the lower case letter o for the sprintf format string,
the sample code you showed used '%0' the number.

-- 
Michael
mich...@thegrebs.com
M: +1-562-MIKEGRB

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




Re: CGI.pm and scrolling list box code error

2011-05-30 Thread Michael Greb
On Mon, May 30, 2011 at 08:48:44PM -0400, John M Rathbun MD wrote:
>print scrolling_list(-name => 'choose',-values=>@terms,-size=>254);

scrolling_list wants a reference for the value list:
print scrolling_list(-name => 'choose',-values=>\@terms,-size=>254);

This should do what you want, when you use '@terms' the array gets
expanded to the list of items in the array, the backslash causes a
reference to the array to be passed instead.  The relevant
documentation is perlref
<http://perldoc.perl.org/perlref.html#Making-References>.


-- 
Michael
mich...@thegrebs.com
M: +1-562-MIKEGRB

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




RE: About the Perl multiple lines problem

2010-01-13 Thread Grove, Michael
At 6:47 PM +0800 1/13/10, Majian wrote:
>Hi,all
>
>There is a problem confused me  for a long time .
>It is:
>
>cat  test.txt
>
>1,
>2,
>3,
>4,
>5,
>6,
>7,
>8,
>9,
>10,
>11,
>
>
>
>Then I want to this result :
>1 2   3  6   9
>4  7 10
>5  8  11
>
>I don't know  how to print the result use the Perl script  clearly.
>Could someone give me some suggestions?

>Here are some snippets to get you started (untested):

>1. open the file:
> open( my $fh, '<', $filename) or die("Can't open file $filename: $!");
>
>2. Read the lines into an array, one line per element:
>   my @lines = <$fh>;
>
>3. Remove the newlines and commas from the end of the strings:
>
> chomp(@lines);
> s/,$// for @lines;
>
>4. Print the lines in any order according to whatever logic you desire:
>
>print "$_ " for @lines[0,1];
> for( my $i = 2; ($i+6) <= $#lines; $i++ ) {
>print "$_ " for @lines[$i,$i+3,$i+6];
>   print "\n";
> }
>
>
>--
>Jim Gibson
>j...@gibson.org

--

Does this occur when you copy a file from one operating system to another in 
binary? (i.e. return carriage character needs to be translated)?

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




RE: Weird CGI.pm issue

2010-01-08 Thread Grove, Michael

param( 'POSTDATA' );


 ADD
 
 6ec973aa3f7a96e43f86b8d2aea0585ba3096c28
5551313
SMS
15551212
 Test message sent from script %%DNAME%% %\xdaTE%% 
ALERT
 
 


ADD

6ec973aa3f7a96e43f86b8d2aea0585ba3096c28
5551313
SMS
15551212
Test message sent from script %%DNAME%% %%DATE%% 
ALERT



http://learn.perl.org/



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




RE: double quotes are needed

2010-01-06 Thread Grove, Michael
Ok, this is my final draft.

Though it is syntactically correct, is it a good way to assign variables?

#!/usr/bin/perl

use strict;
use warnings;

my $first = 0xFF;
my $second = 0377;
my $third = 0b;
my $answer = $first + $second + $third;

print "$first, $second, $third\n";
print "$answer\n";

Mike Grove | AIX System Administrator
OIT - BIO - Server Farms Division
PA Department of Labor & Industry
651 Boas Street Room 124 | Harrisburg, PA 17121
Phone: 717-705-2724 | Fax: 717-783-6364
AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502





-Original Message-
From: Shlomi Fish [mailto:shlo...@iglu.org.il]
Sent: Wednesday, January 06, 2010 1:48 PM
To: beginners@perl.org
Cc: Grove, Michael
Subject: Re: double quotes are needed

On Wednesday 06 Jan 2010 20:38:29 Grove, Michael wrote:
> Thanks.
>
> Is this better?
>
> print "$first, $second, $third","\n";
>

Yes, but you can also write it as:

<<<<
print "$first, $second, $third\n";
>>>>

> 255, 255, 255
> 765
>
> If I put the second set of quotes after the last comma, I get an error.
>

What do you mean by that? How are you writing it?

Also, please avoid top-posting and quote my reply:

http://en.wikipedia.org/wiki/Posting_style

Regards,

Shlomi Fish

> I am only on pg 21 of Learning Perl 5th ed. I am trying as many variations
>  of the examples just to mess around and see what happens with different
>  characters.
>
>
> Mike Grove | AIX System Administrator
> OIT - BIO - Server Farms Division
> PA Department of Labor & Industry
> 651 Boas Street Room 124 | Harrisburg, PA 17121
> Phone: 717-705-2724 | Fax: 717-783-6364
> AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502

--
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Bzr is slower than Subversion in combination with Sourceforge.
( By: http://dazjorz.com/ )

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




RE: double quotes are needed

2010-01-06 Thread Grove, Michael
Shlomi, what is "top posting?" where you said: "please avoid top-posting and 
quote my reply"

Fyi I used use strict; and use warnings;
And got a bunch of global errors to I put "my" in front of all of my variables. 
I have a lot to learn still.


#!/usr/bin/perl

use strict;
use warnings;

my $first = 0xFF;
my $second = 0377;
my $third = 0b;
print "$first, $second, $third\n";
my $answer = $first + $second + $third;
print "$answer\n";

Mike Grove | AIX System Administrator
OIT - BIO - Server Farms Division
PA Department of Labor & Industry
651 Boas Street Room 124 | Harrisburg, PA 17121
Phone: 717-705-2724 | Fax: 717-783-6364
AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502





-Original Message-
From: Shlomi Fish [mailto:shlo...@iglu.org.il]
Sent: Wednesday, January 06, 2010 1:48 PM
To: beginners@perl.org
Cc: Grove, Michael
Subject: Re: double quotes are needed

On Wednesday 06 Jan 2010 20:38:29 Grove, Michael wrote:
> Thanks.
>
> Is this better?
>
> print "$first, $second, $third","\n";
>

Yes, but you can also write it as:

<<<<
print "$first, $second, $third\n";
>>>>

> 255, 255, 255
> 765
>
> If I put the second set of quotes after the last comma, I get an error.
>

What do you mean by that? How are you writing it?

Also, please avoid top-posting and quote my reply:

http://en.wikipedia.org/wiki/Posting_style

Regards,

Shlomi Fish

> I am only on pg 21 of Learning Perl 5th ed. I am trying as many variations
>  of the examples just to mess around and see what happens with different
>  characters.
>
>
> Mike Grove | AIX System Administrator
> OIT - BIO - Server Farms Division
> PA Department of Labor & Industry
> 651 Boas Street Room 124 | Harrisburg, PA 17121
> Phone: 717-705-2724 | Fax: 717-783-6364
> AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502

--
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Bzr is slower than Subversion in combination with Sourceforge.
( By: http://dazjorz.com/ )

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




RE: double quotes are needed

2010-01-06 Thread Grove, Michael
Thanks everyone.

The one line I wrote was a mistake in quote placement for this message:
"print $first, $second, $third\n"

meant

print "$first, $second, $third," "\n"

But I don't want the last comma in the output, so I wrote this with your help:

#!/usr/bin/perl

$first = 0xFF;
$second = 0377;
$third = 0b;
print "$first, $second, $third","\n";
$answer = $first + $second + $third;
print "$answer\n";

or is this way preferred?

#!/usr/bin/perl

$first = 0xFF;
$second = 0377;
$third = 0b;
print "$first, $second, $third\n";
$answer = $first + $second + $third;
print "$answer\n";




Mike Grove | AIX System Administrator
OIT - BIO - Server Farms Division
PA Department of Labor & Industry
651 Boas Street Room 124 | Harrisburg, PA 17121
Phone: 717-705-2724 | Fax: 717-783-6364
AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502





-Original Message-
From: Shlomi Fish [mailto:shlo...@iglu.org.il]
Sent: Wednesday, January 06, 2010 1:48 PM
To: beginners@perl.org
Cc: Grove, Michael
Subject: Re: double quotes are needed

On Wednesday 06 Jan 2010 20:38:29 Grove, Michael wrote:
> Thanks.
>
> Is this better?
>
> print "$first, $second, $third","\n";
>

Yes, but you can also write it as:

<<<<
print "$first, $second, $third\n";
>>>>

> 255, 255, 255
> 765
>
> If I put the second set of quotes after the last comma, I get an error.
>

What do you mean by that? How are you writing it?

Also, please avoid top-posting and quote my reply:

http://en.wikipedia.org/wiki/Posting_style

Regards,

Shlomi Fish

> I am only on pg 21 of Learning Perl 5th ed. I am trying as many variations
>  of the examples just to mess around and see what happens with different
>  characters.
>
>
> Mike Grove | AIX System Administrator
> OIT - BIO - Server Farms Division
> PA Department of Labor & Industry
> 651 Boas Street Room 124 | Harrisburg, PA 17121
> Phone: 717-705-2724 | Fax: 717-783-6364
> AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502

--
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Bzr is slower than Subversion in combination with Sourceforge.
( By: http://dazjorz.com/ )

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




RE: double quotes are needed

2010-01-06 Thread Grove, Michael
Thanks.

Is this better?

print "$first, $second, $third","\n";

255, 255, 255
765

If I put the second set of quotes after the last comma, I get an error.

I am only on pg 21 of Learning Perl 5th ed. I am trying as many variations of 
the examples just to mess around and see what happens with different characters.


Mike Grove | AIX System Administrator
OIT - BIO - Server Farms Division
PA Department of Labor & Industry
651 Boas Street Room 124 | Harrisburg, PA 17121
Phone: 717-705-2724 | Fax: 717-783-6364
AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502





-Original Message-
From: Shlomi Fish [mailto:shlo...@iglu.org.il]
Sent: Wednesday, January 06, 2010 12:45 PM
To: beginners@perl.org
Cc: Grove, Michael
Subject: Re: double quotes are needed

Hi Mike!

On Wednesday 06 Jan 2010 19:27:59 Grove, Michael wrote:
> Can someone tell me why I need double quotes for this to work at the line
>  with: print $first, $second, $third\n;
>
> #!/usr/bin/perl -w
>

Don't use "-w". Add "use strict;" and "use warnings;". Then fix the errors.


> $first = 0xFF;
> $second = 0377;
> $third = 0b;
> print $first, $second, $third\n;

$third\n is invalid code. The "\n" must be placed inside a string.

Regards,

Shlomi Fish

> $answer = $first + $second + $third;
> print "$answer\n";
>
> It only gives this output when I write double quotes "print $first,
>  $second, $third\n";
>
> 255, 255, 255
> 765
>
>
> Mike Grove | AIX System Administrator
> OIT - BIO - Server Farms Division
> PA Department of Labor & Industry
> 651 Boas Street Room 124 | Harrisburg, PA 17121
> Phone: 717-705-2724 | Fax: 717-783-6364
> AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502
>

--
-
Shlomi Fish   http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Bzr is slower than Subversion in combination with Sourceforge.
( By: http://dazjorz.com/ )

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




double quotes are needed

2010-01-06 Thread Grove, Michael
Can someone tell me why I need double quotes for this to work at the line with: 
print $first, $second, $third\n;

#!/usr/bin/perl -w

$first = 0xFF;
$second = 0377;
$third = 0b;
print $first, $second, $third\n;
$answer = $first + $second + $third;
print "$answer\n";

It only gives this output when I write double quotes "print $first, $second, 
$third\n";

255, 255, 255
765


Mike Grove | AIX System Administrator
OIT - BIO - Server Farms Division
PA Department of Labor & Industry
651 Boas Street Room 124 | Harrisburg, PA 17121
Phone: 717-705-2724 | Fax: 717-783-6364
AIX Hot Line 717-525-5598 | AIX Cell 717-329-0502








Re: the classic "which is the fastest way to sort" question

2009-11-09 Thread Michael Alipio
Hi,

 
>
>  Do you need the fastest possible sort? 

I'm not even sure if I really need to worry about all these 
sorting techniques. My program just reads a text file 
(wordlist). It might be megabyte-sized or probably few 
gigabytes (i might also add size checking on this to be
safe with File::Slurp). Then I will give the user an option
of sorting it in various ways, like length, alphabetical,
numerical, frequency of letters, etc. 

I see, so it all boils down to how expensive the 
comparison you're going to implement to fully benefit 
from these techniques. Now comes another question 
for me to find the answer to, how expensive the 
comparisons in my sorting function would be... I 
guess there's no other way for me to find this out 
than to try it out  myself. What's worse is that 
there's also a "depends on the system" factor to 
consider as well. Sometimes I wish perl's motto 
is "there's only one best way to do it" so everyone
would just agree on one way of doing something, 
so everyone would have the same beautiful
and efficient code. For now, I will probably just stick
to using the built-in sort (just for sorting length, 
numbers, and letters), until I have gained enough 
knowledge about why it's necessary to use the 
other techniques, or how to do the benchmark 
myself.


> Philip

> PS your email client has a very long line length, causing my quoting
>  above to go somewhat haywire. I'd recommend setting it to something
> like 74.





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




the classic "which is the fastest way to sort" question

2009-11-09 Thread Michael Alipio
Hi,

i'm planning to sort an input file (which was File::Slurp'ed, most likely 
megabyte-sized file) in various ways. I did some readings and learned several 
methods
that people have come up with in recent years. So to summarize, the default 
sort is fast (uses quick sort), explicit (using sub) is a bit slower, other 
method
that uses caching is faster. Then there's Schwartzian Transform and a packed 
version by Guttman. Seems like everything is clear. Guttman is the fastest,
until I went to cpan. Found Sort::Key, which claims to be the fastest, even 
faster that ST, GRT. Now, before someone says, why not try each one and
see for yourself (which doing such could be another subject for me to learn), 
my question is this: if such faster sorting algorithms exist, why don't they 
just replace the default sort function in Perl?

And for the classical question, given my situation (in combination with 
File::Slurp), which is fastest sort method? (I hope somebody includes this in 
perlfaq in the future).


  

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




must satisfy _unknown_ number of regexp patterns

2009-11-05 Thread Michael Alipio
Hi,

if I have a script that accepts any combination of the 5 or maybe even more 
options, say, option1, option2, option3...


Now, after collecting the options, for each option, there is a corresponding 
regexp pattern. I will then build an if statement, where the test should be, 
all the options entered must match (&&) otherwise, return false.
I'm thinking this can only be done by nested if's:

if ($word =~ /$option1/ && $word =~ /$option2){
  if ($word =~ /$option3/ && $word =~ /$option4){
 if ($word =~ /$optionN/){
print "All pattern matched!\n";
 }
  }
}


Now I'm thinking, it is quite impossible to dynamically create all those if 
tests. Perhaps I can just open a file for writing, write a new perl script 
which will have those codes, and execute it at the end. 

Is there a better way of doing this?









  

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




Re: AW: compact my wordlist generator

2009-10-26 Thread Michael Alipio
Thanks for the advice. Forgive me if I sounded like someone who's frustrated, 
couldn't do his homework asking somebody else for help.

When I was learning C programming, I read that learning those difficult 
algorithms such as bubble sort, quick sort, binary search, is something that 
only programming students have to deal with. 

I have also learned that the best way to learn is by looking at other peoples 
code. So far I managed to write a number of useful perl programs through this. 
I just got frustrated with this particular task I had to accomplish. I've done 
some readings before about those math topics you've mentioned. As I understood, 
permutation is producing all combinations without repetition. A part of my code 
uses the module Algorithm::Permute for this purpose and for the other part 
which produces all possible (repeating) combinations, I have to write this 
code. Somebody gave me an example pseudocode and I tried to convert my code 
into it but I just couldn't do it.

I knew I needed a recursive function, I just didn't know how to start.
What confused me more is that the code I found is a lot different from what I 
was initially thinking. He used the builtin function substr in the code in a 
way that I couldn't figure how it worked.

See below:

my $result = '';

perm(0,2);

sub perm($$){
my ($cur,$max) = @_;

if ($cur>=$max){
 print "$result\n";
return;
}

for(@word){
substr($result,$cur,1)=$_;
perm($cur+1,$max);
}
}

What's the use of double ($$) after sub perm?? Does it have anything to do with 
process IDs (perldoc perlvar says so)?

This line is also confusing:
substr($result,$cur,1)= $_;
 
Substr returns a list, right? The first parameter is the expression, 2nd is the 
offset, and last is the length.
The above line is too cryptic for me. What confused me more is that the return 
value of substr was assigned the $_.


If someone can help me decipher each line, i'll be very happy.



--- On Mon, 10/26/09, Thomas Bätzler  wrote:

> From: Thomas Bätzler 
> Subject: AW: compact my wordlist generator
> To: "begginers perl.org" 
> Cc: "Michael Alipio" 
> Date: Monday, October 26, 2009, 10:40 PM
> Michael Alipio 
> wrote:
> > Can anyone tell me how the code above works? My
> original program must
> > deal with arbitrary length and generate all the
> possible combinations
> > (even repeating) of a particular set. What could take
> me gazillions of
> > for loops for that, somebody just came up with less
> than ten lines.
> > I can just copy and paste the code I found above but I
> want to learn how
> > it works. How could someone write this code so easily
> but when I tried
> > even writing just a pseudocode for it, my head almost
> exploded.
> 
> It probably helps if you have some understanding of the
> underlying mathematics of the problem domain, i.e. in this
> case combinatorics.
> 
> This would also clear up potential misunderstandings viz
> the definition of a permutation ("randomly pick n of m
> elements without putting them back") vs. that of a
> combination ("randomly pick n of m elements while putting
> them back").
> 
> > I want to be a good programmer, but at this rate, I
> don't think I can be
> > one if I will just keep copying and pasting someone
> else's code or
> > downloading modules from CPAN.
> 
> Actually, taking somebody else's code and trying to figure
> out how it works is a good exercise ;-)
>  
> > Can anyone teach me how my own code (the one with
> gazillion for loops),
> > can be converted into a pseudocode then eventually
> into a working sub
> > procedure?
> 
> No, probably not right away. But the good news is that most
> people don't come up with elegant solutions off the top of
> their heads - instead, they will have learned a number of
> basic patterns and/or algorithms for solving common
> problems, and they will have the experience to adapt what
> they know to new problems.
> 
> So, in order to become a better programmer you should look
> at stuff people have been doing before you. Go to your local
> library and borrow a book on Algorithms. Try to implement
> them in Perl. Have a look at the Perl cookbook. If you want
> a challenge, then treat yourself to a copy of "Higher Order
> Perl" by Mark Jason Dominus.
> 
> HTH,
> Thomas
> 
> 





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




Re: compact my wordlist generator

2009-10-26 Thread Michael Alipio
hi,

I have this code, mentioned below:

my @word = qw(a b c );
my $length = @word;
my $char1, $char2, $char3;

if ($length == 3){
for ($char1 = 0; $char1<$len;$char1++){
 for ($char2 = 0; $char2<$len;$char2++){
  for ($char3 = 0; $char3<$len;$char3++){
print "$word[$char1]$word[$char2]$word[$char3]\n";
}}}
}elsif($length == 2){
 for ($char2 = 0; $char2<$len;$char2++){
  for ($char3 = 0; $char3<$len;$char3++){
print "$word[$char1]$word[$char2]\n";
}elsif($length == n){


and so on...
}


Then as suggested (see far below), a recursive function will do what I want.. 
After some googling I found this:


permutate(0,2);

sub permutate($$){

  my ($cur,$max) = @_;
  
  if ($cur>=$max){
 print "$result\n";
 return;
  }

  for(@word){
substr($result,$cur,1)=$_;
perm($cur+1,$max);
  }
}


Can anyone tell me how the code above works? My original program must deal with 
arbitrary length and generate all the possible combinations (even repeating) of 
a particular set. What could take me gazillions of for loops for that, somebody 
just came up with less than ten lines. 
I can just copy and paste the code I found above but I want to learn how it 
works. How could someone write this code so easily but when I tried even 
writing just a pseudocode for it, my head almost exploded. 

I want to be a good programmer, but at this rate, I don't think I can be one if 
I will just keep copying and pasting someone else's code or downloading modules 
from CPAN.

Can anyone teach me how my own code (the one with gazillion for loops), can be 
converted into a pseudocode then eventually into a working sub procedure?




--- On Sun, 10/25/09, Gabor Szabo  wrote:

> > Hi,
> >
> >  I'm trying to write a word list generator which can
> >  generate all possible combinations of n characters,
> within n
> >  set of characters.
> >
> >
> >  So far, this is what I have come up. The only input
> is the
> >  lenght of the password the user wants.
> >



> What about keeping the characters in an array @char
> so you will have
> $char[0], $char[1] etc. a
> 
> nd the loops could be replaced by a recursive function
> call. Something
> like this:
> 
> do_something_for_char($k)
> 
> sub do_something_for_char {
>   my ($k) = @_;
>   return if $k >= $n;
>    do_something_for_char($n+1);
> }
> 
> 
> Gabor
> 





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




split n characters into n chunks

2009-10-25 Thread Michael Alipio
Hi,

How do I split a word into n subsets?

my $word = "thequickbrown"


If I want three subsets I should be able to create:

the
heq
equ

upto

own


Using split function with limit of 3 gives me:

t h equickbrown



Any idea how to do this? I'm thinking maybe I can just split the whole string 
and push each character into array, then loop through the array, getting 3 
elements set in the proces..







  


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




Re: compact my wordlist generator

2009-10-25 Thread Michael Alipio
I was thinking about this recursive thing... thanks for the tip.. will try this 
out.. I hope I can accomplish it.

--- On Sun, 10/25/09, Gabor Szabo  wrote:

> From: Gabor Szabo 
> Subject: Re: compact my wordlist generator
> To: "Michael Alipio" 
> Cc: "begginers perl.org" 
> Date: Sunday, October 25, 2009, 5:06 PM
> 2009/10/25 Michael Alipio :
> > Hi,
> >
> >  I'm trying to write a word list generator which can
> >  generate all possible combinations of n characters,
> within n
> >  set of characters.
> >
> >
> >  So far, this is what I have come up. The only input
> is the
> >  lenght of the password the user wants.
> >
> >  my @set = qw(a b c d e f g h i j k l m n o p q r s t
> u v w
> >  x y z);
> >  my $len = scalar @set;
> >  my $char1;
> >  my $char2;
> >  my $char3;
> >  my $char4;
> >  my $char5;
> >  my $char6;
> >  my $char7;
> >  my $char8;
> >
> >  if ($pwlen == 8){
> >
> >  for ($char1=0;$char1<$len;$char1++){
> >    for ($char2=0;$char2<$len;$char2++){
> >      for ($char3=0;$char3<$len;$char3++){
> >
> >      ... upto
> >
> >      for ($char8=0;$char8<$len;$char8++){
> >
> >  print
> >
>  "$set[$char1]$set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]set[$char7]$set[$char8]\n";
> >
> >  
> >
> >  } elseif ( $pwlen == 7){
> >
> >  for ($char2=0;$char2<$len;$char1++){
> >    for ($char3=0;$char3<$len;$char2++){
> >      for ($char4=0;$char4<$len;$char3++){
> >
> >      ... upto
> >
> >      for ($char8=0;$char8<$len;$char8++){
> >
> >  print
> >
>  "$set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]$set[$char7]set[$char8]\n";
> >
> >  }}}
> >
> >  }
> >
> >
> >  The problem with the code above is that the length
> of words
> >  is hard coded. Only 8 maximum. I'm looking for ways
> on how
> >  to make my code flexible (length can be whatever the
> user
> >  wants ).
> >
> >  My code is limited to 8 chars maximum length plus if
> I want
> >  to increase it, I have to add another set of for
> loops plus
> >  another variable to use, e.g., $char9, char10.. and
> so
> >  on...
> >
> >
> >  Any idea?
> 
> What about keeping the characters in an array @char
> so you will have
> $char[0], $char[1] etc. a
> 
> nd the loops could be replaced by a recursive function
> call. Something
> like this:
> 
> do_something_for_char($k)
> 
> sub do_something_for_char {
>   my ($k) = @_;
>   return if $k >= $n;
>    do_something_for_char($n+1);
> }
> 
> 
> Gabor
> 





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




compact my wordlist generator

2009-10-25 Thread Michael Alipio
Hi,

 I'm trying to write a word list generator which can
 generate all possible combinations of n characters, within n
 set of characters.
 
 
 So far, this is what I have come up. The only input is the
 lenght of the password the user wants.
 
 my @set = qw(a b c d e f g h i j k l m n o p q r s t u v w
 x y z);
 my $len = scalar @set;
 my $char1;
 my $char2;
 my $char3;
 my $char4;
 my $char5;
 my $char6;
 my $char7;
 my $char8;
 
 if ($pwlen == 8){
 
 for ($char1=0;$char1<$len;$char1++){
   for ($char2=0;$char2<$len;$char2++){
     for ($char3=0;$char3<$len;$char3++){
 
     ... upto
 
     for ($char8=0;$char8<$len;$char8++){
 
 print
 
"$set[$char1]$set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]set[$char7]$set[$char8]\n";
 
 
 
 } elseif ( $pwlen == 7){
 
 for ($char2=0;$char2<$len;$char1++){
   for ($char3=0;$char3<$len;$char2++){
     for ($char4=0;$char4<$len;$char3++){
 
     ... upto
 
     for ($char8=0;$char8<$len;$char8++){
 
 print
 
"$set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]$set[$char7]set[$char8]\n";
 
 }}}
 
 }
 
 
 The problem with the code above is that the length of words
 is hard coded. Only 8 maximum. I'm looking for ways on how
 to make my code flexible (length can be whatever the user
 wants ).
 
 My code is limited to 8 chars maximum length plus if I want
 to increase it, I have to add another set of for loops plus
 another variable to use, e.g., $char9, char10.. and so
 on...
 
 
 Any idea?
 
 
       






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




Re: Daemon::Easy and self-killing

2009-10-15 Thread Michael Pobega
On  0, Steve Bertrand  wrote:
> Michael Pobega wrote:
> > I'm using the Daemon::Easy module to write a basic Perl daemon, but I'm
> > wondering if there is a way to stop the daemon from within the script (as
> > opposed to running "./script.pl stop")? Currently I have a subroutine to do
> > this, but it doesn't seem to cleanly erase the pid file.
> >
> >> &killMe {
> >> unlink("/tmp/.idle_kick-$PID.pid");
> >> system("gnome-session-save --force-logout"); # the point of the 
> >> daemon
> >> exit;
> >> }
> >
> > And yes, $PID is pointing to the proper file (I've used 'print' to manually 
> > get
> > the value, and it's all right).
> >
> > I've read all of the documentation for the Daemon::Easy module,
>
> [...]
>
> As someone who is staging to become a CPAN author (but not there yet),
> I'd recommend that you mail the author with your concerns. If the CPAN
> author has honoured their responsibility, then there will be a
> responsive email address within the perldoc of the project.
>

I'll probably shoot him an e-mail then. I didn't realize the module was at such
a low version.

> fwiw, to answer your question about not cleanly erasing the pid, I would
> first manually ensure the code ( it has comments that contain typos,
> does the code? ), then I would focus on file-system permissions that the
> user who is executing the code has. ( ensure the code before you allow
> it to 'unlink' as a privileged user ).

The user definitely has permissions to erase it; at one point I had this:

> unlink("/tmp/pid-file")
>   ? print LOG "Success!"
>   : print LOG "Failure";

And everytime I ran the program it would print "Success!" to the log file --
yet the file would still be there (and even printing the name of the file
proved nothing...the name was definitely correct)

>
> I'd find something else or re-write it, if I were you...
>

Extending it is a possibility, but at my current level (midway through reading
"Intermediate Perl" it's a bit out of the question. Perhaps in the next month
or so I can spruce it up a bit, though.

Note: Steve, sorry about replying to you originally. I wasn't thinking when I
hit the reply button.

--
  http://fuzzydev.org/~pobega
http://identi.ca/pobega

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




Daemon::Easy and self-killing

2009-10-14 Thread Michael Pobega
I'm using the Daemon::Easy module to write a basic Perl daemon, but I'm
wondering if there is a way to stop the daemon from within the script (as
opposed to running "./script.pl stop")? Currently I have a subroutine to do
this, but it doesn't seem to cleanly erase the pid file.

> &killMe {
> unlink("/tmp/.idle_kick-$PID.pid");
> system("gnome-session-save --force-logout"); # the point of the daemon
> exit;
> }

And yes, $PID is pointing to the proper file (I've used 'print' to manually get
the value, and it's all right).

I've read all of the documentation for the Daemon::Easy module, but it isn't
exactly what I'd call verbose (on the contrary, it's as simplistic as the
code...)

--
  http://fuzzydev.org/~pobega
http://identi.ca/pobega

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




complex split (when delimiter appears in one of the fields)

2009-06-11 Thread Michael Alipio

Hi,

I have a string that looks like this:

my $string = "1, 3, 0. 0. 0. 0, 22, Zak',adfk $&! mac., ";


Basically, there are seven fields. after the bird, everything up to the last 
comma is the 5th field. 6th field is blank.

Now my problem is splitting it and extracting the 5th field.

If I will do a (split/,/,$string)[-2]) then i will only get "adfk $&! mac."
I need to get the entire "Zak' , adfk $&! mac."




  

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




2 minutes and 8 second (how do i convert it to 02:08)??

2009-06-11 Thread Michael Alipio

Hi, 

I have a program that computes the number of elapsed minutes and seconds.


if the outputs are:

2 minutes, and 8 seconds.

How do I print those two values to look like "Elapsed time: 02:08"

Thanks!


  

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




Re: variables gets shared to child but resets back after exiting fork

2009-05-27 Thread Michael Alipio

hey,

thanks for the reply. The "-|" was the right option for me. The reason is 
because I only need to get the first 4 lines of output of the external program. 
"-|" was perfect because I don't have to base the stopping on time but rather 
on the number of output lines. Another problem solved!!!
Till next time!





--- On Wed, 5/27/09, Chas. Owens  wrote:

> From: Chas. Owens 
> Subject: Re: variables gets shared to child but resets back after exiting fork
> To: "Michael Alipio" 
> Cc: "begginers perl.org" 
> Date: Wednesday, May 27, 2009, 7:45 PM
> On Wed, May 27, 2009 at 07:24,
> Michael Alipio 
> wrote:
> >
> > Sorry about the indention... must be the mail client
> i'm using.
> > I need to fork because the external program I want to
> run inside the child runs infinitely. I want to have a timer
> running in the parent and after that, kill the child.
> Without forking, I have to do a pkill myprogname
> > I'm reading the perlipc now.. nothing so far..
> snip
> 
> 
> You don't need a fork for that, you need alarm[1] and block
> eval[2]:
> 
> eval {
>     local $SIG{ALRM} = sub { die "timeout\n" };
>     alarm 3; #die after three seconds
>     #operation that needs to die if it is not
> finished in three seconds;
>     alarm 0; #turn off the alarm clock
>     1; #make the eval return true
> } or {
>     #propagate the error unless it is the
> timeout
>     die $@ unless $@ eq "alarm\n";
> };
> 
> 
> 
> 1. http://perldoc.perl.org/functions/alarm.html
> 2. http://perldoc.perl.org/functions/eval.html
> 
> -- 
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the
> ability to read.
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
> 




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




Re: variables gets shared to child but resets back after exiting fork

2009-05-27 Thread Michael Alipio

Sorry about the indention... must be the mail client i'm using.
I need to fork because the external program I want to run inside the child runs 
infinitely. I want to have a timer running in the parent and after that, kill 
the child. Without forking, I have to do a pkill myprogname
I'm reading the perlipc now.. nothing so far..

--- On Wed, 5/27/09, Chas. Owens  wrote:

> From: Chas. Owens 
> Subject: Re: variables gets shared to child but resets back after exiting fork
> To: "Michael Alipio" 
> Cc: "begginers perl.org" 
> Date: Wednesday, May 27, 2009, 7:15 PM
> On Wed, May 27, 2009 at 05:42,
> Michael Alipio 
> wrote:
> >
> > Hi,
> >
> > I have to run an external program but the program does
> not termination on some conditions, e.g, ping, will not exit
> unless you specify -c or some other circumstances.
> >
> >
> > Now I what I want to do is:
> >
> > my @array;
> > die "Cannot fork myprog" unless (defined my $pid =
> fork)
> > if ($pid==0){
> > open MYPROG, "myprog |" or die "Cant run myprog";
> > my $timeout = 0;
> > while (){
> > exit(0) if $timeout == 3;
> > push @array, $_;
> > sleep 1;
> > $timeout++;
> > }
> >
> > waitpid($pid, 0);
> > print "@array\n";
> >
> >
> > The problem with the code above is that @array goes
> back to its initial state after exiting the child. No
> contents are printed. I even tried references but it didn't
> work as well.
> >
> > If I don't use fork, I the way I would kill the
> process is by doing a call to pkill. With fork, it would be
> much easier with exit. However the output of external
> program gets discarded.
> >
> > Can you think of any workaround for this?
> snip
> 
> 
> Variables are not shared between parent and child. 
> The values of the
> parent's variables are copied to the child at the time of
> the fork.
> You really need to read perldoc perlipc[1].  And you
> need to learn how
> to indent code.  Leaving your code all against the
> left side of the
> screen makes it hard to read.
> 
> Of course, the biggest question is why are you bothering to
> fork in
> the first place?  Why not just say
> 
> my $program = "myprog";
> 
> open my $pipe, "-|", $program
>     or die "Cant run $program: $!";
> 
> my @array;
> for (1 .. 3) {
>     last unless defined(my $line =
> <$pipe>);
>     push @array, $line;
> }
> 
> close $pipe;
> 
> 
> 
> 1. http://perldoc.perl.org/perlipc.html
> 
> -- 
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the
> ability to read.
> 




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




variables gets shared to child but resets back after exiting fork

2009-05-27 Thread Michael Alipio

Hi,

I have to run an external program but the program does not termination on some 
conditions, e.g, ping, will not exit unless you specify -c or some other 
circumstances.


Now I what I want to do is:

my @array;
die "Cannot fork myprog" unless (defined my $pid = fork)
if ($pid==0){
open MYPROG, "myprog |" or die "Cant run myprog";
my $timeout = 0;
while (){
exit(0) if $timeout == 3;
push @array, $_;
sleep 1;
$timeout++;
}

waitpid($pid, 0);
print "@array\n";


The problem with the code above is that @array goes back to its initial state 
after exiting the child. No contents are printed. I even tried references but 
it didn't work as well.

If I don't use fork, I the way I would kill the process is by doing a call to 
pkill. With fork, it would be much easier with exit. However the output of 
external program gets discarded.

Can you think of any workaround for this?











  

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




script to control web browser (enter captcha text manually)

2009-05-23 Thread Michael Alipio

Hi,

I need to register a few accounts on a website that uses captcha. It's just a 
few accounts but it's a very daunting task because there are so many fields to 
fill up. Is there a way I can do this in perl? What I want is that my script 
will fire up the browser, access that particular registration page, then all I 
have to do is to fill in the captcha verification field, the rest have been 
filled already, after wards, pressing enter, the script will retrieve the 
registration page again obtaining a fresh captcha image in the process.


  

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




Re: two nested hashes, one subroutine, after calling, my second hash disappears

2009-05-21 Thread Michael Alipio

Hi,


> >     
>    $$postdata{'login:command/username'} =
> ($username eq '')?'':$username;
> 
> $$postdata{'login:command/username'} is usually written as
> $postdata->{'login:command/username'}.  You compare
> $username to '' and if it is equal to '' then you return ''
> and if it is not equal to '' you return $username.  The
> test is superfluous, just assign $username.


I tried that one. I ran the code against the web application and proxied the 
requests, the form parameter 

e.g, &username=admin&password=&blah=

If I will just assign $username or $password I will end up with a non blank 
value +0x (something like that) and the application would throw an error.

Ex.: the following parameter/value is sent to the web app.

&username=admin&password=+0x

While if I only have &username=admin&password=&nextparameter

The web app will respond properly.



> 
> From what I understand from reading the documentation the
> second argument to POST should be an array reference but you
> are passing it a hash reference.

I'm not sure about this but the first sub was called and executed properly.
The second sub won't execute because the $postdata in there is empty.



> > 
> > When I run my program, I get an error:
> 
> An error or a warning?  An error will usually halt the
> program while a warning will not.


I think it is an error, because the program halts. It is supposed to do some 
more routines after those two.

> 
> It is hard to tell from the limited amount of code provided
> what exactly is causing your problem.
> 

What else can I do?
What other information can I provide?







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




two nested hashes, one subroutine, after calling, my second hash disappears

2009-05-21 Thread Michael Alipio

Hi,

I thought I had it all figured out. Hash within hashes really made my code 
cleaner until I came up with this code:

While looping, I was creating a key 'webloginpostdata' with value of anonymous 
hash as seen below;

  $all_ap{$_}->{'webloginpostdata'} = {
'var:main' => 'menu',
'testwebcm' => 'webcm',
'login:command/username' => '',
'login:command/password' => '',
'var:connecting1' => '0'
};



Now following the creation above, i'm creating another key 'webadminpostdata' 
which has a value of an anonymous hash again.

  $all_ap{$_}->{'webadminpostdata'} = {
  'var:main' => 'menu',
  'var:style' => 'style5',

  'settings/username' => $all_ap{$_}->{'webuser'},
  'settings/password' => $all_ap{$_}->{'webpass'},
  'settings/password_confirm' => $all_ap{$_}->{'webpass'},
  'settings/idle_timeout' => '30'
};



Then there's two subroutines. The first one ("loginweb") is called. If 
successful, the next one ("changewebpass") is called


my $login_status = loginweb($all_ap{$_}->{'webloginurl'}, 
$all_ap{$_}->{'webloginpostdata'});
if ($login_status eq 'success'){

   ## Call next subroutine
   
my $setpassword = changewebpass($all_ap{$_}->{'webadminurl'}, 
$all_ap{$_}->{'webadminpostdata'});
if ($setpassword ne 'success'){
  print "Can\'t change password\n";
}else{
  print "New login created:\n\t username: $all_ap{$_}->{'webuser'} \n\t 
password: $all_ap{$_}->{'webpass'}\n";
}



"loginweb" sub is really simple:


sub loginweb{

my $url = shift;
my $postdata = shift;
my $username;
my $password;

open PASSLIST, "appasswd.txt" or die $!;
while (){
$username = (split / === /, $_)[0];
$password = (split / === /, $_)[1];
chomp ($username, $password);
print "\nTrying username: \'$username\'  password: \'$password\'";
  $$postdata{'login:command/username'} = ($username eq '')?'':$username;
  $$postdata{'login:command/password'} = ($password eq '')?'':$password;
my $res = $ua->request(POST $url, $postdata);
if ($res->content =~ /Basic\s+Home\s+Menu/){
print " SUCCESS!!!\n";
return 'success';
}else{
next;
}

}



Finally, here's the "changewebpass"


sub changewebpass{

my $url = shift;
my $postdata = shift;
my $res = $ua->request(POST $url, $postdata);

if ($res->is_success){
 return 'success';
}else{
 return 'failed';
 }

}



When I run my program, I get an error:

"Need a field name at (eval 11) line 1"


That's all. No mention of line number, or whatever. Perhaps that is because the 
error was not a syntax error but a perl module error.
Further investigation showed that after calling loginweb,
my $all_ap($_}->{'webadminpostdata'} gets emptied.

calling 'changewebaccess', nothing is being assigned to $postdata. That is why 
i'm getting that error.



Any idea where to look into?? In my code before, I only had to declare the 
actual hashes:

my %webloginpostdata = (...);
my %webadminpostdata = (...);

Then pass their references to the sub routines: ie,
loginweb(\%webloginpostdata)


I didn't have any troubles doing so.














  

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




How does printf able to receive a pointer when passing it a string constant?

2009-05-13 Thread Michael Alipio


I have a c code that looks like this:

#include

main (){
char girl[] = "anna";
char boy[] = "jude";
stringcopy(boy, girl); /* copy boy to girl */
printf("%s", girl); 

}

void stringcopy(char *b, char *g){

while ((*g++ = *b++) != '\0')
;
}


It prints fine...
However if I replace the stringcopy call arguments with "jude", "anna"
it compiles fine but i get segmentation fault when running.


How come printf can accept variable names as well as constant strings such as: 

printf ("%s", girl); 

and

printf ("Hello World\n");


My stringcopy function only accepts pointers. Shouldn't I be passing pointer to 
the first element of "anna" when passing the string constant "anna"?? )


How does printf print a string constant then?



  

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




Cross compiling to mipsel

2009-05-12 Thread Michael Alipio

Hi,

I've searched the web and didn't find anything useful. Is there anyway to cross 
compile my perl code to mipsel? or do i have to learn C?? 


  

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




AW: Problem with threaded Math::GMP

2009-04-28 Thread SCHWARTZKOPFF, Michael, Dr. (Extern)
-Ursprüngliche Nachricht-
Von: Brian J. Miller [mailto:wigg...@danconia.org] 
Gesendet: Dienstag, 28. April 2009 14:15
An: SCHWARTZKOPFF, Michael, Dr. (Extern)
Cc: beginners@perl.org
Betreff: Re: Problem with threaded Math::GMP

SCHWARTZKOPFF, Michael, Dr. (Extern) wrote:
> Hi,
> 
> I wanted to the Net::SSH::Perl but perl complained about a missing 
> Math::GMP. So did a cpan install Math::GMP and finally found 
> /usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Math/GMP.pm
> on my system. But when I add this path to my lib and started my 
> program I get the error:
> perl: symbol lookup error:
> /usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Math/GMP
> /G
> MP.so: undefined symbol: Perl_Gthr_key_ptr
> 
> Searching for this error I found out that the library is for threaded 
> perl. Now my questions:
> Why does cpan install a threaded version when my normal perl does not 
> use threads?

> You state "normal perl"... Do you have more than one installed? What distro 
> and version are you using? System perl is almost always at >  /usr and 
> usually threaded, but often a non-threaded perl is installed elsewhere, say 
> /usr/local. You would need to specify the correct perl when executing cpan 
> (or more precisely the correct cpan).

I only have one perl installed rpm -qa | grep perl gives:
perl-5.8.8-14.7
My system is a SuSE Linux Destop 10.1
find /usr -name "perl" 2>/dev/null
/usr/bin/perl

> Howto make cpan install a "normal" verison, which my system can use?
> 

It should be correct. Can you double check with,

> perl -V

And provide the output.

perl -V
Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:
osname=linux, osvers=2.6.8-24-default, archname=x86_64-linux
uname='linux cp001785 2.6.8-24-default #4 fri mar 4 14:39:37 cet 2005 
x86_64 x86_64 x86_64 gnulinux '
config_args=''
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef 
usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=define uselongdouble=undef
usemymalloc=n, bincompat5005=undef
  Compiler:
cc='/yaprod/comp/intel/compiler81/em64t/bin/icc', ccflags 
='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='Intel(R) C++ gcc 3.0 mode', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
alignbytes=8, prototype=define
  Linker and Libraries:
ld='/yaprod/comp/intel/compiler81/em64t/bin/icc', ldflags =' 
-L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.3.3'
  Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: USE_64_BIT_INT USE_64_BIT_ALL USE_LARGE_FILES
  Built under linux
  Compiled at Mar 17 2005 09:47:26
  @INC:
/yaprod/freeware/Linux_x86_64//lib/perl5/5.8.4/x86_64-linux
/yaprod/freeware/Linux_x86_64//lib/perl5/5.8.4
/yaprod/freeware/Linux_x86_64//lib/perl5/5.8.4/x86_64-linux/x86_64-linux
/yaprod/freeware/Linux_x86_64//lib/perl5/5.8.4/x86_64-linux
/yaprod/freeware/Linux_x86_64//lib/perl5/5.8.4/x86_64-linux

> As an aside if you are planning to only use SSH version 2 you don't need a 
> functional Math::GMP, it is only required for version 1. > Math::Pari is used 
> for version 2.

> Thanks for any help.

I gave up using the perl ssh libs and use system calls.

Michael.
-- 
MTU Aero Engines GmbH
Geschaeftsfuehrung/Board of Management: Egon W. Behle, Vorsitzender/CEO; Dr. 
Rainer Martens, Dr. Stefan Weingartner, Reiner Winkler
Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Klaus 
Eberhardt
Sitz der Gesellschaft/Registered Office: Muenchen
Handelsregister/Commercial Register: Muenchen HRB 154230


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




Problem with threaded Math::GMP

2009-04-28 Thread SCHWARTZKOPFF, Michael, Dr. (Extern)
Hi,

I wanted to the Net::SSH::Perl but perl complained about a missing
Math::GMP. So did a 
cpan install Math::GMP
and finally found 
/usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Math/GMP.pm
on my system. But when I add this path to my lib and started my program
I get the error:
perl: symbol lookup error:
/usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Math/GMP/G
MP.so: undefined symbol: Perl_Gthr_key_ptr

Searching for this error I found out that the library is for threaded
perl. Now my questions:
Why does cpan install a threaded version when my normal perl does not
use threads?
Howto make cpan install a "normal" verison, which my system can use?

Thanks for any help.

Mit freundlichen Gruessen / Best regards

Michael Schwartzkopff
MTU Aero Engines GmbH
Abteilungsbezeichnung ()
Department () 
Dachauer Str. 665
80995 Muenchen
Germany

Tel +49 (0)89 14 89-5534
Fax +49 (0)89 14 89-99485
[optional] Mobile +49 (0)174 343 28 75
mailto:michael.schwartzko...@mtu.de
http://www.mtu.de

-- 
MTU Aero Engines GmbH
Geschaeftsfuehrung/Board of Management: Egon W. Behle, Vorsitzender/CEO; Dr. 
Rainer Martens, Dr. Stefan Weingartner, Reiner Winkler
Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Klaus 
Eberhardt
Sitz der Gesellschaft/Registered Office: Muenchen
Handelsregister/Commercial Register: Muenchen HRB 154230



Controlling screen output. Print something then afterwards replace it

2009-04-22 Thread Michael Alipio

Hi,

Is it possible to print something and then replace what you have printed with a 
different value?

Say I have a program that watches a logfile and prints the current number of 
lines.

after sleeping for n seconds, it will print the number of lines again. But i 
don't want to print it below the old output. I want to replace it with the new 
output.

That is, if I have the previous output as:

"The log contains: 30 lines"

After 10 seconds, I don't want to see two lines saying:

"The log contains: 30 lines"
"The log contains: 40 lines"

Instead I only want to see:
"The log contains: 40 lines"

Is this possible without removing all other previous output? I mean Only that 
particular line will change. This is commonly seen on programs which updates 
their output in realtime.














  

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




sleep exactly after n seconds (sleep finishing longer than specified)

2009-04-22 Thread Michael Alipio

Hi,

I have a script that forks a child. at the parent, i have a line that tells it 
to sleep for n seconds. Once the 3 seconds have passed, it will kill the child 
process.

I noticed that most of the time, sleep doesn't count exact seconds.. most of 
the time it's longer. Is there any way to sleep precisely for n seconds?


  

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




trouble with nested forks() (keep spawning twin process)

2009-04-16 Thread Michael Alipio

Hi,

I have this code:

die "Could not fork command1!" unless defined (my $command1_pid = fork);
if ($command1_pid == 0){
  open EXTERNAL_PROG1, "external_prog1 |" or die "Can't run external_prog1";

  while (){
if (/pattern/){
  die "Could not fork command2" unless defined (my $command2_pid = fork);
  die "Could not fork command3" unless defined (my $command3_pid = fork);

if ($command2_pid == 0){
   `external_prog2`
 }
}
 waitpid($command2_pid,0);

if ($command3_pid == 0){
  `external_prog3`;
} 
 waitpid($command3_pid, 0);

}
}



That is, run external_prog1 and watch the output.. as soon as it sees a 
particular pattern, run two other external commands at the same time. However, 
with the above code, I keep getting duplicated external_prog2 process everytime 
i run the script. I need to track both PIDs of external_prog2 and 3 as I need 
to kill them later in the code. However, i'm having trouble running them at the 
same time.
if I will put a "kill 15, $command3_pid" right after the first waitpid, i will 
surely kill one of those two command 2 process. I tried several places to put 
"die" lines and "waitpids" but I couldn't get it right. It's either they don't 
run at the same time or they will run but command 2 has a twin brother.

Any idea how to solve this chicken and egg problem?




  

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




Re: Turn off $ anchor greedy behavior

2009-04-14 Thread Michael Alipio

Aha, found it.. The split returned a list and you've just sliced it. giving 
[-1] means the list will start running through the elements backwards. 


--- On Tue, 4/14/09, Michael Alipio  wrote:

> From: Michael Alipio 
> Subject: Re: Turn off $ anchor greedy behavior
> To: "Perl Beginners" , "John W. Krahn" 
> Date: Tuesday, April 14, 2009, 10:02 PM
> > 
> > Or use split and return the last field:
> > 
> > $ perl -le'
> > my $string = "boy, pig, 123, 123:412adbd, d0g,
> > lajdlf134><<_ lkadsf !234,\n";
> > my $value = ( split /,\s+/, $string )[ -1 ];
> 
> Another mind bogling example... :-)
> I thought I would do:
> 
> my @value = ( split /,\s+/, $string );
> print $value[6];
> 
> How could your example, have printed the last field using [
> -1 ]?
> Can I also print say, the 3rd field using this trick?
> 
> 
> 
> 
> 
> 
> > print $value;
> > '
> > lajdlf134><<_ lkadsf !234
> > 
> > 
> > 
> > 
> > 
> > John
> > -- Those people who think they know everything are a
> great
> > annoyance to those of us who do.-- Isaac
> Asimov
> > 
> > -- To unsubscribe, e-mail:
> beginners-unsubscr...@perl.org
> > For additional commands, e-mail:
> beginners-h...@perl.org
> > http://learn.perl.org/
> 
> 
>   
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/


  

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




Re: Turn off $ anchor greedy behavior

2009-04-14 Thread Michael Alipio


> 
> Or use split and return the last field:
> 
> $ perl -le'
> my $string = "boy, pig, 123, 123:412adbd, d0g,
> lajdlf134><<_ lkadsf !234,\n";
> my $value = ( split /,\s+/, $string )[ -1 ];

Another mind bogling example... :-)
I thought I would do:

my @value = ( split /,\s+/, $string );
print $value[6];

How could your example, have printed the last field using [ -1 ]?
Can I also print say, the 3rd field using this trick?






> print $value;
> '
> lajdlf134><<_ lkadsf !234
> 
> 
> 
> 
> 
> John
> -- Those people who think they know everything are a great
> annoyance to those of us who do.-- Isaac Asimov
> 
> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/


  

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




Re: AW: Turn off $ anchor greedy behavior

2009-04-14 Thread Michael Alipio



> my $string = 'boy, pig, 123, 123:412adbd, d0g,
> lajdlf134><<_ lkadsf !234,';
> 
> if( $string =~ m/,\s*([^,]*),[^,]*$/ ){
>   print "$1\n";
> }

How could you guys write this so simple? My regexp was twice this long.
the regexp after \s* tells perl to match anything (0 or more) that is not a 
comma, right? how come it did not match pig? pig is also followed by comma, 
right? so pig should be captured by ([^,]*), right? I guess perl really looks 
for a match starting from the end of the line.


The string actually looks like this:

ABCD1:5C, 2009-04-14 13:01:24, 2009-04-14, 5, 23, ABC, , , -1, 187, 0, 1.2.3.4, 
20, lkasd123 as_!23:<<>s @12ff,


My Regexp looks like this:
/\.\s+\d+,\s+\d+,\s+(.*),$/


It matches from the comma at the end of the line up to .4 when you go 
backwards. By going as far as this, I can be assured that perl won't find any 
more match, but the regexp looks ugly.

What is wrong with my version?
I think if in the future, if perl finds a line which is not ending in a pattern 
exactly like my regexp then it will fail, however yours i guess won't.


> 
> __END__
> 
> Depending on the input data size it might worthwhile to
> look at rindex() and substr() instead of using a RE.
> 




> HTH,
> Thomas




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




Turn off $ anchor greedy behavior

2009-04-14 Thread Michael Alipio

Hi,


I have a $string that is separated by , and space;

boy, pig, 123, 123:412adbd, d0g, lajdlf134><<_ lkadsf !234,


Now I want to capture the string(s) between last two commas. It consists of 
anything upto 32 characters. that is, right after d0g,\s+ up to the last 
character before the last comma at the end of the line.

if I do something like

(my $value) = $_ ~= /,\s+(.*),\s+$/;

$value would start matching from "pig" because when I used $ and it looked 
back, the first thing it would match is ", pig upto the end of the line"

I wonder how you could match only the pattern which is nearest to the end of 
the line having used $ anchor.

To get around this, I could split the lines push each comma delimited string 
into an array and finally print the last element which is a lot of work to do.

Is there some sort of turning of greedy behavior of the $ anchor?














  

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




  1   2   3   4   5   6   7   8   9   10   >