Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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
The simplest possible pattern match defeats me
1 direct reply — Read more / Contribute
by logan
on May 22, 2013 at 22:35
    I'm having a hard time with what seems like a really simple issue: comparing a string to a variable. I've pored over the Camel book and the docs for a disturbing amount of time and I'm stumped by something that hasn't been an issue for me for 15 years. For some reason when I run the code below I keep get warnings about uninitialized values in the pattern match.
    while ($allChanges->[$k]) { $logger->info("Change $k was to the ", $allChanges->[$k]->getField( +), " field of testCase ", $allChanges->[$k]->getKey(), " on createdDa +te ", $allChanges->[$k]->printCreatedDate(), " Old String = (", $allC +hanges->[$k]->getOldString(), ") New String = ", $allChanges->[$k]->g +etNewString()); local $oldString = $allChanges->[$k]->getOldString(); local $newString = $allChanges->[$k]->getNewString(); $logger->debug("oldString = (", $oldString, ")"); $logger->debug("newString = (", $newString, ")"); print Dumper($oldString); if ($oldString eq "Automated") { # Line 103, the one that gives all + the trouble. $logger->debug("old string = Automated: ", $oldString); $logger->debug("new string: ", $newString); } } package ChangeItem; sub new { my $class = shift; my $logger = get_logger("ChangeItem"); my $self = { } ; if (@_) { $self->{line} = shift @_; } $self->{key} = 0; $self->{field} = 0; $self->{oldString} = 0; $self->{newString} = 0; $self->{createdDate} = 0; $self->{version} = 0; bless ($self, $class); return $self; } sub setOldString { my $self = shift; $self->{oldString} = shift; } sub getOldString { my $self = shift; return $self->{oldString}; }
    When I run the code I keep getting warnings about uninitialized values in the pattern match
    INFO main:::80: Change 0 was to the Automated field of testCase HIREX- +16861 on createdDate 2013-05-13 10:16:05 Old String = (To Be Automate +d) New String = Ready For Integration DEBUG main:::84: oldString = (To Be Automated) DEBUG main:::85: newString = (Ready For Integration) $VAR1 = 'To Be Automated'; Use of uninitialized value in pattern match (m//) at weeklyAutomationC +hanges.pl line 103. Use of uninitialized value in pattern match (m//) at weeklyAutomationC +hanges.pl line 103.
    The value of $oldString is populated by a call to ChangeItem::getOldString(). I can see that it has a value because it's being printed. I've checked that the value is a simple scalar by sending it to Data::Dumper ($VAR1 = 'To Be Automated';). I feel like I'm missing something incredibly basic but at this point I'm baffled.

    -Logan
    "What do I want? I'm an American. I want more."

Win32::API pointers / NULL
1 direct reply — Read more / Contribute
by ghardy
on May 22, 2013 at 19:30

    I'm getting a crash on the last line of the following Win32::API Call to a National Instruments driver DLL.

    # Working Equivalent in C # uInt32 data=0x00000000; # int32 written; #DAQmxWriteDigitalU32(taskHandle,1,1,10.0,0,&data,&written,NULL) #int32 __CFUNC DAQmxWriteDigitalU32 (TaskHandle taskHand +le, int32 numSampsPerChan, bool32 autoStart, float64 timeout, bool32 +dataLayout, const uInt32 writeArray[], int32 *sampsPerChanWritten, bo +ol32 *reserved); my $functionDAQmxWriteDigitalU32 = Win32::API->new('nicaiu','DAQmxWrit +eDigitalU32','IIIFIPPP','I','_cdecl'); my $numSamps = 1; #int32 my $autoStart = 1; #bool32 my $timeout = 10.0; #float64 my $GroupByChannel = 0; #bool32 my $writearray = pack ('N4',0,0,0,0); my $sampsPerChanWritten= pack("N4",0,0,0,0); my $reserved = 0; # NULL * $return = $functionDAQmxWriteDigitalU32->Call($outTaskHandle,$numSamps +,$autoStart,$timeout,$GroupByChannel,$writearray,$sampsPerChanWritten +,$reserved);

    Previous function calls using the outTaskHandle are working fine, I'm pretty sure the problem is in the $writearray parameter (which I need to set to some hex value like 0xF7), the $sampsPerChanWritten which is modified by the C function, or the $reserved pointer which is supposed to be NULL. I've tried many different assignments to $writearray and $sampsPerChanWritten with no luck.

    I'm new to Perl, Win32::API and perlmonks so I apologize for formatting issues.

JSON Structure Question
2 direct replies — Read more / Contribute
by omegaweaponZ
on May 22, 2013 at 16:22
    This goes back to a previous post, which I've somewhat resolved myself, but still have one outstanding issue: I am looking to grab and store the value of each overall json line value first. Example: from the below code, I want to actually read and store in a variable through a while loop and store 1, 2, 3, etc.
    { "1": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"}, "2": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"}, "3": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"} }
    (etc...) I currently already can store subject1's value as well as the array of subject2 and grab its subject3 value.
    my $jsonfeed = (above json format!) my $json = new JSON; my $data = $json->decode($jsonfeed); my $value = "$data->{1}->{subject1}"; foreach my $array(@{$data->{1}->{subject2}}){ my %hash = (); $hash{subject3} = $array->{subject3}; }
    So this is all nice, but I need to store the first value of each {} sequence which is listed here as 1{}, 2{}, 3, etc as well in a variable, and then loop the whole thing in one giant while or foreach loop. I can't seem to grab every value, however, of $data->{$_}. Anyone have a good idea?
how to unpack a C struct with length array preceding data array
4 direct replies — Read more / Contribute
by johnlumby
on May 22, 2013 at 15:28

    my perl app receives a buffer containing this format

    { short lengths[2]; char data[???]; } where there are two items in data, of length lengths[0] and lengths[1] respectively.

    I have tried and tried to unpack this into 4 perl variables in a single unpack() call and failed. I had to resort to two unpack()'s, the first to extract the lengths followed by something like

    eval('($junk1 , $junk2, $data0, $data1) = unpack "ssA' . $data0_length + . "A" . $data1_length . '",$rcvd_buf;');

    which works fine, but can some kind Monk tell me how to do this in one unpack.

Mac Space in Path
3 direct replies — Read more / Contribute
by Anonymous Monk
on May 22, 2013 at 14:26

    I've not been able to solve the problem of space bands in paths on Mac.

    chomp (my $metadata_file = <>); $metadata_file =~ s/\s$//; open FILE, "$metadata_file"; $metadata = join '', <FILE>;

    It currently produces a "readline() on closed filehandle FILE" if there is a space in the path. I've done a lot of research and the answer is quoting the path. I think I've done that. I'm running perl5.10.0 on MacOS 10.6.8.

    Any help would be greatly appreciated.

Question about inheritance of WWW::Mechanize
2 direct replies — Read more / Contribute
by ryo0ka
on May 22, 2013 at 13:25
    Hi monks, I just registered. Thanks in advance! I want to use WWW::Mechanize::get in an inherited class's "get" subroutine, but it does not export any error (like "GETting...") even while the Internet access is out. See my code:
    package MyMech; use base qw(WWW::Mechanize); sub new { my $class = shift or die $!; my $self = $class->SUPER::new; return bless $self, $class; } sub get { my $self = shift; $self->SUPER::get(@_); }
    I think the get routine should work just like the base class' one, but it never die when it fails GETting. When I call the class and use the get subroutine while the Internet access is out, it just pass through the GETting error without saying anything and $mech->title produces "Uninitialized..." error. It works perfectly when the access is not out. Does anybody know why it happens? Thank you so much!
pdftotext pass options
1 direct reply — Read more / Contribute
by welle
on May 22, 2013 at 13:02

    Hi monks

    On a Windows machine I am using pdftotext to bunch convert pdf files into plain text. Using the following, I get no problems:

    system("$path/pdftotext","-nopgbrk","$path_my_pdf","$path_my_pdf.txt") +;

    I now want to add the encoding option "-enc UTF-8", so I try

    system("$path/pdftotext","-enc UTF-8 -nopgbrk","$path_my_pdf","$path_m +y_pdf.txt"); or simply system("$path/pdftotext","-enc UTF-8","$path_my_pdf","$path_my_pdf.txt +");

    but it doesn't work. What am I missing? Thanks

    SOLVED

    system("$path/pdftotext","-enc", "UTF-8","$path_my_pdf","$path_my_pdf. +txt");
system perl api fails with exit code 65280 on Win 2003
3 direct replies — Read more / Contribute
by Prakash Babu
on May 22, 2013 at 10:02

    I have perl script that is executed from a Application server using java on Windows 2003.

    my $zipExec='C:/zip.exe'; my @cmd = ($zipExec, "-rq", $destinationPath, "."); print "Executing command @cmd\n"; $syscode = system(@cmd); my $error = $!; print "Return code = $syscode \n"; print "Error = $error\n";

    It fails with the following error message.

    Return code = 65280
    Error = No such file or directory

    I have ensured that C:/zip.exe files exists and is executable. I tried executing other system binaries like cmd.exe but ran into the same issue.
    My question is what could be causing this issue like
    i. some environment setting is wrong and interfering with the system api and hence it is not able to load the binary.
    ii. The $PATH variable in this environment is greater than 1024 characters. Is the length of this variable a concern or some paths set in this variable is causing this issue


    thanks,
    Prakash
object creation
2 direct replies — Read more / Contribute
by *alexandre*
on May 22, 2013 at 09:52
    Hi, I rewrite some perl code and I found a problem creating a new object here is my package

    And into another module I'm trying to create a DB object like this way
    my $db = DB->new(); but I'm getting the following exception
    Can't locate object method "new" via package "DB" at LoadProperties.pm line 8.
perl in a container (lxc or other)
No replies — Read more | Post response
by djzort
on May 22, 2013 at 07:03
    Im curious if someone would be so kind as to share their experiences setting up a minimal perl container in lxc, openvz, bsd jails, linux-vserver or even chroots.

    App::Staticperl (http://software.schmorp.de/pkg/App-Staticperl.html) looks like it might be a good starting point - if i wanted to avoid a stripped down installed of <favourite distro or bsd>

    The ideal outcome would provide a container with mcpan and a given version of perl. Possibly some fusion of perlbrew and some dark magic to cook up the perl version then drop it in the container.

    Use case is to wrap up apps and put resource limits on them. PAAS like really. I know uwsgi can use namespaces and what not, if someone has used that - please share!

Add your question
Title:
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?
    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 chanting in the Monastery: (5)
    As of 2013-05-23 03:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best material for plates (tableware) is:









      Results (473 votes), past polls