Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

The Monastery Gates

( #131=superdoc: print w/ replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
HTML Parsing (ick)
4 direct replies — Read more / Contribute
by dbarron
on Aug 19, 2014 at 14:55
    Ok, I need to parse webpages (that I wrote, but has been modified by others), and extract pertinent information stored within <div> </div> tags of class 'listing'. I'll list a sample entry below and then detail what I wish to parse out of it, with the format of another sample. Hopefully this will make sense and I'll gladly accept any advise as to which modules to use to make this easier.
    <div class="listing"> Agave parryi&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: normal;">Parry's agave</span> <br>$20.00&nbsp; 3 quart&nbsp;&nbsp;&nbsp; $12.00 Quart <br><span id="native">Native</span>&nbsp;&nbsp;&nbsp; Sun to part shade&nbsp; Zones 5-10&nbsp; Family: <i>Amaryllidaceae</i> <br>From the Southwest comes this lovely agave.&nbsp; Thick spiny leaves adorn this hardy agave.&nbsp; Ultimate clump size is about 36" with each leaf being maybe 5" across. The flower stalk can reach 12 feet tall. Please plant in well drained soil in a place where children don't play. <span id="hummingbird">Hummingbirds</span> </div>
    Ok, what I'd like to get out of this (and there's a lot more html junk around it to ignore) is:
    Latin name (ie agave parryi)
    Common name (Parry's agave)
    Pot price ($20.00)
    Pot size (3 quart)
    Pot price ($12.00)
    Pot size (quart)
    Origin: Native
    Exposure: Sun to part shade
    Hardiness: 5-10
    Family: Amaryllidacea
    Text description:From the Southwest comes this lovely agave.  Thick spiny leaves adorn this hardy agave.  Ultimate clump size is about 36" with each leaf being maybe 5" across. The flower stalk can reach 12 feet tall. Please plant in well drained soil in a place where children don't play.
    Special Features: Hummingbirds (there's others of those...but I can handle generalization (I think))
    Ok, sorry for such a long post...but I wanted to give a good thorough example.
Perl Concatenate vs Append Operator
5 direct replies — Read more / Contribute
by nande9
on Aug 19, 2014 at 12:14

    I have a somewhat general question about the Perl concatenate operator and the append operator.

    First, here is the example straight from Learning Perl (p.29)

    # append a space to $str $str = $str . " ";
    # same thing with assignment operator $str .= " ";

    My question: Are either of these method more "correct" or preferred for speed or syntactical reasons?

    Any information is greatly appreciated.

    -- Nick
Build a module distribution from just .packlist?
1 direct reply — Read more / Contribute
by mpersico
on Aug 19, 2014 at 08:39

    Many of the references I've found to .packlist files are for maintaining them or finding the appropriate one for a module. What I am looking for (before I write it) is a script/module that will USE the .packlist to create a tarball of the already deployed module for further deployment.

    Background: I have reference machines (one per OS) where I build Perl. Initial version builds on those machines are tarballed up, pushed out to production machines with no build tools - not even "make" - and untarballed. Currently, new and updated modules are added to these reference copies and the whole of the Perl reference copy is tarballed up and pushed. I'd prefer to be more granular if only from a psychological standpoint: pushing out a new module version is less intimidating-sounding than pushing out the whole distribution. So...

  • Does anyone know of such a beast?
  • If not, how about some namespace suggestions when I write it myself?
  • Thank you.

Net:SFTP:Foreign put issue
1 direct reply — Read more / Contribute
by rpachon
on Aug 18, 2014 at 16:00
    I am using Net:SFTP:Foreign to upload files and even though my program is just calling the put command, the server side person says that I am requesting a list (ls) command with every put. Is it really the Foreign SFTP put issuing an ls command or is this something the server program is doing? thanks
Your opinion about a book
5 direct replies — Read more / Contribute
by Stefany
on Aug 18, 2014 at 15:52
    Hello colleagues.

    I seek your wisdom. My Bday is coming up - and I was thinking of getting this book as a present - This book

    because you can get it for 1 cent second-hand and it is 1k pages. However, the book was published 2000 !!! Do you think I will have any benefit from it since it has been published 14 years ago, OR I will have benefit from it since all I would need to do is look up the newest functions? Thanks a bunch!
Removing and replacing values from an array.
2 direct replies — Read more / Contribute
by douggie305
on Aug 18, 2014 at 11:34

    Hello all, I just started using perl, and this is my fist attempt and any sort or programming/scripting.

    I would like to make a script that takes a file read from standard input then creates 3 arrays out it, the file contains IP addresses and URLs delimited with [] around the period, and after each there is white space followed by a description.

    I want to first remove the description. In VI I would use %s/ .*//. to do this I would assume the same regex would work in the script.

    Next I want to remove the braces and the period and replace it with just a period again in VI that would be %s/\[.\]/\./g

    Then have what remains (just the IPs and URLs with out any braces or descriptions) put into an array that I will do more editing with, I have the last bit of code figured out I've been testing with the original file already having the [] and descriptions removed, Its just that the file's content will change every time I need to run this script so if I could make the script replace as well as the other functions it would save me a lot of time.

    I don't have much code because I don't know where to start after I get the text into the script. I would like the new text placed in an array name @list after the braces and descriptions have been removed then I can take parts of that array and add them to 2 others one name @ips and the other @urls kinda self explanatory what my intent is but like I said I don't have the faintest idea where to start. Please help! Thanks in advance for any and all help!

    #!/usr/bin/perl use warnings; use strict; foreach my $line (<STDIN>){ chomp $line; #remove extra words and braces. }
How to run perl5.21.3 as "perl"
7 direct replies — Read more / Contribute
by syphilis
on Aug 18, 2014 at 06:39
    I've installed current blead into ~/bleadperl.
    There is no file named "perl" in ~/bleadperl/bin - instead it's called perl5.21.3, and I've been running scripts as 'perl5.21.3', but that gets a bit tedious.
    Also, when I inadvertently type 'perl' then the system perl gets invoked - and I certainly don't want to run *it*. So, I did this:
    sisyphus-sis@debian-sis:~/comp/$ cd ~/bleadperl/bin sisyphus-sis@debian-sis:~/bleadperl/bin$ ln -s perl5.21.3 perl sisyphus-sis@debian-sis:~/bleadperl/bin$ cd ~ sisyphus-sis@debian-sis:~$ which perl /home/sisyphus-sis/bleadperl/bin/perl sisyphus-sis@debian-sis:~$ perl -le 'print $^X;' /usr/bin/perl sisyphus-sis@debian-sis:~$ echo $PATH /home/sisyphus-sis/bleadperl/bin:/usr/local/bin:/usr/bin:/bin:/usr/loc +al/games:/usr/games sisyphus-sis@debian-sis:~$ perl5.21.3 -le 'print $^X;' /home/sisyphus-sis/bleadperl/bin/perl5.21.3 sisyphus-sis@debian-sis:~$
    I don't get it ... 'which perl' reports blead, but if I run 'perl' I still get the system perl. Why is that ?
    I've also tried removing the 'perl' symlink in bleadperl/bin and, renaming 'perl5.21.3' to 'perl' - same thing happens:
    sisyphus-sis@debian-sis:~/bleadperl/bin$ rm perl sisyphus-sis@debian-sis:~/bleadperl/bin$ which perl /usr/bin/perl sisyphus-sis@debian-sis:~/bleadperl/bin$ mv perl5.21.3 perl sisyphus-sis@debian-sis:~/bleadperl/bin$ which perl /home/sisyphus-sis/bleadperl/bin/perl sisyphus-sis@debian-sis:~/bleadperl/bin$ perl -le 'print $^X;' /usr/bin/perl
    So now I've renamed ~/bleadperl/bin/perl back to ~/bleadperl/bin/perl5.21.3:
    sisyphus-sis@debian-sis:~/bleadperl/bin$ mv perl perl5.21.3 sisyphus-sis@debian-sis:~/bleadperl/bin$ cd ~ sisyphus-sis@debian-sis:~$ which perl /usr/bin/perl sisyphus-sis@debian-sis:~$ perl5.21.3 -le 'print $^X' /home/sisyphus-sis/bleadperl/bin/perl5.21.3
    and I guess I'll just have to continue calling it as 'perl5.21.3' until I can find a way to call it as 'perl'.

    I've also checked that I don't have to call it precisely 'perl5.21.3' - eg I can call it 'perlzzz' and it's still runnable.
    But I can't run it as 'perl'.

How to get public folders path in Perl Dancer
1 direct reply — Read more / Contribute
by pookybear
on Aug 17, 2014 at 14:33

    Probably a silly question, but how do I get the path to the /public folder in Dancer?

    I want to store/read csv files under the public folder, but don't know if Dancer offers any convenience methods to get the base path to the public folder.

    The error I get when trying to create a file by saying:

    open(FILE, ">>", "myapp/public/file.csv") or die "$!";


    No such file or directory in /ur/share/perl5/Dancer/ l. 98

    I'm not sure why it's going to

Croak, return et al.
3 direct replies — Read more / Contribute
by packetstormer
on Aug 16, 2014 at 11:39

    Hello Monks

    I have a 'best practice' query. Suppose the simple script below. I want to (or maybe I don't!) create a module that might fail under certain circumstances. However, I would like to continue on from the calling script. I realise I could use 'return' but then I'd have to catch that value

    So, with that in mind does anyone have any thoughts on how the package below might be rewritten to allow the calling script continue? I could also just print "SPLAT";return but I am unsure what the norm is.
    You can see that I could use eval (commented out) but again, I am unsure of the best practice!?

    #!/usr/bin/perl use strict; use Data::Dumper; my @r = (1..5); foreach (@r) { print "Start for $_\n"; my $splat = Splat->new(); #eval { $splat->splat() }; #if ($@) {next} if ($_ ==1) { print "Never getting this far\n" } } print "Nor this far\n"; package Splat; use Carp qw(croak); sub new { my $class = shift; my $self = {}; bless $self,$class; return $self; } sub splat { my $self = shift; croak "SPLAT!" if ! $self->{splat} } 1;
exec function does not return command prompt
4 direct replies — Read more / Contribute
by casman46
on Aug 15, 2014 at 14:33

    I am experimenting with using the fork and exec functions to spawn a child process and execute a different script. My ultimate goal is to spawn multiple child processes from the parent without waiting for any of the children to complete. My first attempt is to merely spawn a single child. The parent code is as follows:

    #!/usr/bin/perl use strict; use warnings; my $pid; if( $pid = fork ){ print "In test1 the parent pid is $$; the child pid is $pid\n"; } else { die "could not fork a process: $!" unless defined $pid; exec ( "/liwidata/dev/tmp/jmg/dev/library/" ) or print STD +ERR "couldn't exec test program: $!"; } print "All done!\n";

    The child code is as follows:

    #!/usr/bin/perl use strict; use warnings; print "In the pid is $$\n";

    When I execute the parent script I receive the following output:

    /liwidata/dev/tmp/jmg/dev/library> ./ In test1 the parent pid is 21348; the child pid is 21349 All done! /liwidata/dev/tmp/jmg/dev/library> In the pid is 21349

    As you can see the command prompt does not appear at the conclusion of the child script. I must enter a Ctrl-C in order to get it back. What am I doing wrong?

Sort and Access Array of Hash
3 direct replies — Read more / Contribute
by PerlSufi
on Aug 15, 2014 at 11:36
    Hello Monks,
    Solved: I actually need the key of the variable $lowest below:
    use strict; use warnings; use List::Util qw(min); use Data::Dumper; my $products_and_prices; my $sellable_products = [ { one => 1, two => 2, }, ]; for my $prod ( @{$sellable_products} ) { push @{$products_and_prices}, { $prod->name => $prod->price, }; } my $lowest = min values $products_and_prices; print Dumper($lowest);
    Any insight is greatly appreciated.
Automation of Multiple Windows of Firefox using WWW::Mechanize::Firefox
1 direct reply — Read more / Contribute
by lalvin
on Aug 15, 2014 at 07:10
    Hi Monks, I've two Firefox windows each with a unique user profile and both have MozRepl installed and started. I would like to know if it is possible to use WWW::Mechanize::Firefox to automate tasks for the two Firefox windows separately. When I create a new instance of WWW::Mechanize::Firefox, it seems that it can only control one window. I appreciate any help on this issue.
New Meditations
How realistic is an extended absence?
9 direct replies — Read more / Contribute
by ksublondie
on Aug 15, 2014 at 13:17
    I've been working for the same small, local company since college (12 years -- CS degree) and the sole programmer for the last 7...5 of which have been almost exclusively from home. I love my job, the company is great, can't ask for a better boss, I'm able to work independently and come up with my own projects. But lately, I've been contemplating staying home* to watch the kiddos (currently 3 all <=5). I'm flat out burned out and my priorities have shifted.

    How realistic is it to quit my job for an extended adsence (5+ years) and later return to a programming/IT position? Am I going to be pigeon holed into the baby-track? Will I be untouchable & irrelavant?

    * EDIT: "staying at home" = quitting my job/programming. For clarification, I have been working at home full-time with the kiddos from day one. Always in the past, it worked rather well. It was all they ever knew. My parenting style is rather "hands off" (not to say I neglect my children, but I make sure their needs are met while teaching them to be independent and doing things for themselves if it's within their capability). As a result, they have amazing attention spands and are capable of entertaining themselves. Plus a fortune invested in baby gates helps. Toddlers running around are less distracting than my coworkers and all the drama, politics, meetings about the next meeting, etc.

    I don't know if it's the addition of #3, or their ages requiring more mental stimulation, or #2 being a holy terror...or a combination thereof...but it's not working so smoothly anymore. I'm debating about quitting completely. I can tell myself to "stay in the loop" independently, but realistically, I know I won't. I already feel irrelavant since I'm not physically in the office.

RFC: interface for a DBD::Proxy-like module client-side DSN
No replies — Read more | Post response
by MidLifeXis
on Aug 14, 2014 at 09:22

    I made mention of this in the CB the other day, but didn't get many responses, so I thought I would ask it here to perhaps get a wider audience and set of responses.

    I am modifying a copy of DBD::Proxy/DBI::ProxyServer so that instead of specifying the entire server-side DSN on the client side, you instead specify a known name of a handle to a configured DSN on the server side. Using this and implementing the sql section of the configuration to another set of known queries would allow the client to use a DBI compliant data source without needing to have the server-side implementation details available. I am also looking to update the connection / user / query definition sections to make them more able to be isolated from one another.

    • Does a client-side DSN along the lines of dbi:Router:hostname=$hostname;port=$port;dsn=dbi:router:$remotename seem like a reasonable interface? [clarification: $hostname and $port are for connecting to the proxy / routing server, not the database -- that is fully configured on the routing server] Is there something (currently) better to base this on than DBD::Proxy/DBI::ProxyServer?
    • Does the name seem sensible?
    • Should I just try to incorporate this directly into the DBD::Proxy core itself?
    • Any other thoughts / previously invented wheels / ideas?

    The major use case I have for this is to standardize access to all of the little bits of information I have to use for my applications which currently exist in different data stores (CSV/TSV, SQLite, ldap, ...) in order to migrate them into a more manageable setup without impacting the application code. This type of configuration would also allow for the mockup of a testing set of data, migration to different platforms, ...


    • pgbouncer was mentioned as a similar tool
    • Added description of my use case
    • Added a clarification of what the host/port refer to


Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-08-20 07:19 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (107 votes), past polls