Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Seekers of Perl Wisdom

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

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
Which is better software design
2 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 27, 2015 at 03:40

    (Sorry for English) Hi, currently I'm making an web application using only CGI module
    And I'm not using frameworks like Catalyst,Dancer.. because I love DIY.
    But programming with MVC pattern I have some trouble.

    1. refine data and pass to the function vs pass raw data to the function and function refines the data

    for example :

    search_by_tags(split ',', $cgi->param('tags'));


    search_by_tags($cgi->param('tags')); # split called inside this functi +on

    2. I have two controller classes Controller::Admin and Controller::Auth and there is one bootstrap file
    I wonder which is better design :

    Each Controller class calls $self->get_view()->print_blabla() as a result and that method prints a piece of HTML


    Controller returns a piece of HTML and bootstrapping script prints it.
    for example: use Controller::Admin; Controller::Admin->new()->run(); ###Controller/ sub run(){ my $auth = Controller::Auth->new(); $auth->loggedin() or $auth->require_login(); return; # that prints + login page # #Do some tasks if the user has logged in # }
    versus use Controller::Admin; print Controller::Admin->new()->run(); ###Controller/ sub run(){ my $auth = Controller::Auth->new(); $auth->loggedin() or return $auth->require_login(); # that RETURNS + login page # #Do some tasks if the user has logged in # }
How can I get a single record from Google Contacts based on a phone number?
1 direct reply — Read more / Contribute
by Anonymous Monk
on Mar 26, 2015 at 19:37

    I don't know if this is even possible, let alone how to do it, but what I'd like to develop is a perl script that would accept as input a 10 digit USA/Canada telephone number and match it to a record in Google Contacts, then return the name associated with that record.

    One problem is that Google does not attempt to normalize numbers in their contacts database, therefore in a given contact the phone number might include spaces, hyphens, parenthesis, etc. Basically all non-numeric characters would need to be stripped before the comparison is made. The only exception is where ::: appears, that seems to separate two similar items of the same type in the same field, such as two different phone numbers of the same type. And in any one record there are several fields that can potentially contain phone numbers. Anyway what I really want to to is type in 9999999999 (with the 9999999999 replaced by the actual ten digit number) and have it find the record containing that number in my Google Contacts, and print the associated name, and I have no idea where to start. Any help would be appreciated!
Including modules exclusively for testing with ExtUtils::MakeMaker
1 direct reply — Read more / Contribute
by lackita
on Mar 26, 2015 at 18:43

    I'm trying to wrap up some modules to put on CPAN, but I'm having some difficulty configuring ExtUtils::MakeMaker correctly.

    I've got a module, Point, that's used in my test files, but not in the main part of the codebase. I'd like it to be included when running tests, but not be part of the general installation.

    I've googled around some, and read the documentation and source of ExtUtils::MakeMaker, but to no avail. Is there a canonical way to include these kinds of files?

Help with file test operators
1 direct reply — Read more / Contribute
by justame
on Mar 26, 2015 at 15:41

    I using perl v5.8.4 on a HPUX platform, i have a script that needs to be able to determine if a file is for today or not.
    My thought was to use the file test operators in perl, so i did a small test script posting the file and various test operators.
    My problem is that every file has the same test results.

    foreach my $logfile ( <./report*> ) { chomp($logfile); chomp(my @ll = `ll $logfile`); print "\n\n--------------------------------\n@ll\n"; printf ("%22s %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n", $logfile, -M + _, -A _, -C _, -r _, -w _, -O _); }

    file test returns the same for all files.

    ---------------------------------------------------------- -rw-rw-r-- 1 not_me mygroup 50555 Mar 25 16:44 ./report.txt ./report.txt 0.99 0.00 0.99 1.00 1.00 1.00 ---------------------------------------------------------- -rw-rw-r-- 1 me mygroup 38322 Oct 22 19:34 ./report.txt. +bak ./report.txt.bak 0.99 0.00 0.99 1.00 1.00 1.00 ---------------------------------------------------------- -rw-rw-r-- 1 me mygroup 38322 Oct 22 19:34 ./report.txt. +sav ./report.txt.sav 0.99 0.00 0.99 1.00 1.00 1.00 ---------------------------------------------------------- -rw-r--r-- 1 not_me mygroup 38322 Oct 22 19:09 ./report.txts +av ./report.txtsav 0.99 0.00 0.99 1.00 1.00 1.00 ---------------------------------------------------------- -rw------- 1 not_me mygroup 38322 Oct 22 19:09 ./report.txts +av2 ./report.txtsav2 0.99 0.00 0.99 1.00 1.00 1.00 ---------------------------------------------------------- -rw-rw-r-- 1 me mygroup 41397 Jul 31 2014 ./report_7_30 +.txt ./report_7_30.txt 0.99 0.00 0.99 1.00 1.00 1.00

    Any Ideas why this is happening?

Search element of array in another array
4 direct replies — Read more / Contribute
by better
on Mar 26, 2015 at 15:30

    Hello monks,

    I'm trying to compare two arrays. I know there are many ways to go: After trying, I ended up with use List::MoreUtils qw {any};

    It works fine, in a testing environment, with two small arrays defined within the script

    my @cleanwords = qw (hut hat); my @allwords = qw (hit het hat); foreach my $var (@cleanwords) { if (any { $var eq $_} @allwords) { print "Found: ",$var, "\n"; } else { print $var," not found\n"; } }

    But the process doesn't work, after reading a textfile (list of words) into an array called @allwords. For reading I use:

    use File::Slurp::Tiny 'read_file'; my @allwords = read_file ($ref);

    The array is definetely filled with all the words of the textfile. But no matches are found.

    I think the problem might be, the whole list is probably "slurped" into one element of the array only.

     print scalar @allwords;

    reports back: '1'

    But why are all words printed nicely one beneath the other doing:

    foreach (@allwords){ print "allwords: ",$_,"\n"; }

    Result is:

    allwords: hastig







    It looks almost like a display of sperate elements. Alomost, because 'allwords:'should be printed in front of every word.

    Well, I think I have to learn more about creating arrays from a file.

    It's a special challenge, regarding the functionality of the script, because @allwords should contain all words of the German language

    The idea behind is to check, which element of a list of random letter combinations of varying size is a proper German word

    Any helpful comments appreciated


    P.S.: A step forward: I tried IO::ALL and scalar @allwords reports 10 elements, means all words of the textfile are handed over into the array. But still no matches found.

What is (a => b => c) ?
4 direct replies — Read more / Contribute
by philgoetz
on Mar 26, 2015 at 15:29

    What does this do?

    @x = (a => b => c);

    There's a lot of that in the program I'm looking at. As far as I can tell, it's the same as

    @x = (a, b, c);
XML::CSV out of memory
3 direct replies — Read more / Contribute
by slugger415
on Mar 26, 2015 at 12:03

    Hello, I am using XML::CSV to parse a very large (500MB) CSV file and convert it to XML. I keep getting an "out of memory" error during the parse.

    Is there a way to "purge" data to free up memory during this process, like you can with XML::Twig? (Though I don't see anything about handlers in the doc....)


    my $csv_obj = XML::CSV->new( error_out => 1 ); $csv_obj->{column_headings} = \@heads; my $status = $csv_obj->parse_doc($file);


(OT) A different kind of 'combinatorics'
4 direct replies — Read more / Contribute
by BrowserUk
on Mar 26, 2015 at 09:59

    Given the 16 x 4-bit patterns: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

    Is it possible to combine them is such a way that results in a single, length unspecified, binary string that only contains each of those 16 bit patterns (in any-aligned four bit field) exactly once?

    Ie. if you start with 0000, then the next pattern must start with a 1; else the 0000 repeats immediately.

    That is: 00000001 contains '0000' at offset 0; (0000)0001 but also at offsets: 1 0(0000)001, 2 00(0000)01 and 3 000(0000)1; which is what must be avoided.

    So, if you start with 0000 & 1000: 00001000 then the repeated '0000' is avoided; but the no matter what you put next:

    000010001xxx 0001 repeats 0(0001)(0001)xxx 000010000xxx 0000 repeats (0000)1(0000)xxx

    Beyond a brute force examination of all the permutations, which would be doable for 16 x 4 bits, but not for much bigger, is there some algorithm for performing such a combination?

    This reminds me of something I've seen at some point, but the only thing that's coming out of my brain at the moment is Gray Codes, but I can't see how to apply it.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
can't use string as an array ref
3 direct replies — Read more / Contribute
by fionbarr
on Mar 26, 2015 at 09:58
    Would someone please explain what't going on here?
    Can't use string ("1") as an ARRAY ref while "strict refs" in use at r line line 455. foreach my $line ( @{ $server_list_hash{$server} } ) {
Beginner here - basic help
3 direct replies — Read more / Contribute
by xr6turbo
on Mar 26, 2015 at 09:09

    Hey Monks, Just starting off in perl (and programming in general) and need to do an exercise but a bit confused on the process.

    Trying to create a script that will ask the user to enter a number between 1 and 5 and for it to print a colour represented e.g. if they enter 1, Blue comes up or 3, red gets printed. I've done a bit of research and I know I need to create an array (@) but not too clear on how to do so.

    After that I need to assign an emotion to the colour e.g. blue = calm, red = angry. I'd also like to know how to incorporate modulus into this so on even/odd number inputs I can print it out (think ill need an if/else statement for this?)

    At the end I'd like it to look like this:

    Please enter a number between 1 and 5:


    Blue. Even. Calm

    So far I've got the code below and have no idea how to finish or even progress, any ideas?

    print "Please enter a number between 1 and 5 (inclusive) below:"; my $number = <STDIN>; chomp($number); my @colours = ("red", "green", "blue", "purple", "black"); my %table = ( 1 => "angry" 2 => "sick" 3 => "calm" 4 => "worried" 5 => "sad" );

Add your question
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 wandering the Monastery: (9)
    As of 2015-03-29 14:39 GMT
    Find Nodes?
      Voting Booth?

      When putting a smiley right before a closing parenthesis, do you:

      Results (631 votes), past polls