Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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
Accessing and array of hashes
2 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 26, 2014 at 09:37
    Hi Monks!
    I have this code structure and after passing the data to the sub routine “test” inside of the module, I am trying to accesses the items in the arrays, but I am getting an error saying that this is not a has reference.
    What is the correct syntax to access each element once it gets passed to the sub without a loop?
    Here is a sample that shows what I am trying to do:
    use strict; user warnings; use info; use Data::Dumper; ... foreach my $in (@{$data{$key}}) { push @data , { name => $in{$key}[0]{ name }, add => $in{$key}[0]{ add }, street => $in{$key}[0]{ street }, city => $in{$key}[0]{ city }, zip => $in{$key}[0]{ zip }, state => $in{$key}[0]{ state }, }; } ... # Call info.pm and send data. info::test(\@data); ... # End data.pl file ... # file info.pm ... package info; use strict; use warnings; use Data::Dumper; ... sub test{ my ($test_data) = @_; print Dumper $test_data->{name}; } 1;

    Thanks for looking!
sendmail not returning error info
2 direct replies — Read more / Contribute
by gsee
on Nov 26, 2014 at 05:19

    Hi

    I have written a script which calls the system sendmail, which in most cases works well.

    But when it fails on the close statement i am getting nothing back in $!

    Here is the code:

    if ( close(MAIL) ) { logger("DEBUG: Email sent to: $toList", 0); } else { logger("CRITICAL: Email Failed. $!", 1); }

    The logger subroutine is a simpler print to file and exit if second parameter is 1

    Is there something I am missing here? I really need to know why the close statement is failing so I can do something about it.

Perl structure to Javacript-ready JSON
4 direct replies — Read more / Contribute
by Jeppe
on Nov 25, 2014 at 08:21
    Esteemed monks, I'm essentially trying to escape the contents of a JSON structure.
    my $hashref = { abc => "abc'abc" };
    This should become
    {"abc":"abc\'abc"}
    , and it must work for blessed references as well. I'm currently using the JSON module, but I'm not married to it. Ideally, this would have been resolved by a hook in the JSON module - but that does not seem to be available. What other options do I have?
about Term::ReadLine and it's imported function
3 direct replies — Read more / Contribute
by Discipulus
on Nov 24, 2014 at 08:10
    Hello monks,
    i used readline::rl_basic_commands as only way to have autocompletion working in win32. if i remember correctly i found the mention here.

    I had used this sub in some programs based on various Strawberry distros without any problem.

    Now i have a new program i would like to run on Win32 as in Linux and it uses only core modules.
    I developped on my strawberry Perl but when tried on the Linux box it complains about that missing sub:
    Undefined subroutine &readline::rl_basic_commands called at...
    So i changed the call in something like:
    if (exists &readline::rl_basic_commands){&readline::rl_basic_commands( +keys %cmds);}

    Now on Linux works (without autocompletion), but using that syntax on win32 made the first time intialization of available commands not working. The following working example shows my problem:
    #!perl use strict; use warnings; use Term::ReadLine; $ENV{TERM}=undef; my $term = Term::ReadLine->new('xxx'); my %cmds = (a=>1,b=>2); # THIS WORKS &readline::rl_basic_commands(keys %cmds); # THE FOLLOWING CHECK DOES NOT WORK if (exists &readline::rl_basic_commands){print "BEFORE WHILE EXISTS +\n"; &readline::rl_basic_commands(keys %cmds);} while ( defined ( $_ = $term->readline( '>') ) ) { print "$_\n"; } continue{ # THIS CHECK WORKS INDEED! if (exists &readline::rl_basic_commands){print "IN CONTINUE EXISTS\ +n"; &readline::rl_basic_commands(keys %cmds);} }

    Where and when the sub is defined?
    There is safe way to deal with it?
    There is a way have it working on both Linux and Win32, even in the sad case without autocompletion?

    Thanks for the attention.
    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Regular expression for a comma separated string
6 direct replies — Read more / Contribute
by naderra
on Nov 23, 2014 at 18:22

    Hi,

    I would like to define a regular expression that matches strings consisting of two sub-strings separated by a single comma. Each sub-string may not be empty, and consists exclusively and without repetition of the characters 'A', 'G', 'C' and 'T'. Thus, the pattern should match strings such as:

    A,G
    AG,CT
    TC,CA <- correct, 1st and 2nd sub-strings may have characters in common
    ( as long as these are not repeated within the sub-string ).
    GAT,CGA
    CGAT,TG <- correct, sub-strings may be of different length.
    etc ...

    and should not match:

    ,G <- missing 1st sub-string
    ACGT <- missing comma
    X,A <- incorrect character X
    AA,G <- repetition of character A in 1st substring
    AC,GGC <- repetition of character G in 2nd sub-string
    ATGA,TGG <- repetition in both sub-strings
    ATCXG,AAC <- incorrect character X and repetition in 2nd
    sub-string
    etc ...

    So far I have:

    /^(?=[ACGT]{1,4},[ACGT]{1,4}$)(?!.*(.).*\1.*,)(?!,.*(.).*\1).*$/

    /^(?=[ACGT]{1,4},[ACGT]{1,4}$)(?!.*(.).*\g{1}.*,)(?!,.*(.).*\g{1}).*$/

    also tried joining the capture groups with:

    /^(?=[ACGT]{1,4},[ACGT]{1,4}$)(?!.*(.).*\g{1}.*,.*(.).*\g{2}).*$/

    Now, (?=[ACGT]{1,4},[ACGT]{1,4}$) seems to match the "two sub-strings separated by a single comma" and "consists exclusively of the characters 'A', 'G', 'C' and 'T'" through out the string;

    (?!.*(.).*\1.*,) seems to match "without repetition" up to the comma.

    However, (?!,.*(.).*\1) appears not to be ensuring that it doesn't match a repeated character after the comma.

    I'd greatly appreciate replies with clues and/or patterns that help with the desired matching.

    Using perl v5.18.2

    Thanks in advance

    Robert

Replacing builtin macro languages with perl -- how difficult?
3 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 23, 2014 at 00:22
    I keep getting involved in projects where a big software package has a hand-rolled macro language that is pathologically deficient. I'd love to replace such languages with Perl and expose the underlying data without needing to copy it or pipe into a separate perl process. Can anyone comment on how difficult this might be? Are there any examples of this being done?
Verify syntax of large JSON files
1 direct reply — Read more / Contribute
by ron800
on Nov 22, 2014 at 22:00
    Hello, I've searched through this group, but no one seems to have the same issue. I want to parse large JSON files to see if the syntax is correct. I found examples but they all seem to want to parse from a string. I want to do something like this:
    use JSON::Parse 'assert_valid_json'; unless (valid_json ($json)) { # do something } eval { assert_valid_json ('["xyz":"b"]'); }; if ($@) { print "Your JSON was invalid: $@\n"; } }
    My files are multiple megabytes and reading them into a string for parsing is not realistic. Any suggestions would be appreciated.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-11-29 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (203 votes), past polls