Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Seekers of Perl Wisdom

by gods
on Sep 07, 1999 at 20:28 UTC ( #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
Counting ID on the basis of batch
2 direct replies — Read more / Contribute
by rohan.mohapatra47
on Sep 23, 2016 at 03:02

    My input file is somewhat like this

    CC225|Rosha|xyz|2221|b1 CC225|Rosha|xyz|2230|b1 CC225|Rosha|xyz|2221|b1 CC225|Rosha|xyz|2221|b1 CC225|Roshw|xyz|2222|b2 CC225|Roshw|xyz|2230|b2 CC222|Roqsha|xyz|2222|b1 CC222|Roqsha|xyz|2244|b1 CC222|Roqsh|xyz|2221|b2 CC222|Roqsh|xyz|2111|b2

    Output will be

    CC225|b1|4|Rosha CC225|b2|2|Roshw CC222|b1|2|Roqsha CC222|b2|2|Roqsh

    It counts ID on the basis of batches & prints it.

    Can someone help?

complex data structures
2 direct replies — Read more / Contribute
by perltux
on Sep 22, 2016 at 21:42
    Hi, I have the following data structure:

    my @AnData; my %AN=(data => \@AnData);

    Now if I want to reference an element of the array @AnData via the hash %AN, I found by trial and error that I have to use: \$AN{data}[0x16]

    Why do I need the extra backslash there?

    I would have thought that $AN{data}[0x16] would already be a reference to the element 16 of array @AnData, as $AN{data} is a reference to the array @AnData. To access the value I would have expected to have to use: $$AN{data}[0x16] instead of $AN{data}[0x16].

    Thanks in advance for any clarification.
    A confused perltux
Perl 5.12.2 Data Structures
5 direct replies — Read more / Contribute
by hennesse
on Sep 22, 2016 at 19:34
    My web host is stuck on Perl 5.12.2 Many of the examples in the 5.24 perldsc just do not work. Like: 5.24 docs sez $thirdList{$itemArea}[$itemId] = [a,b,c] will work, but it doesn't. The push job does though. Need some old geezers to explain "how it used to be done". I'm creating a hash of an array of an array.
    use strict; use warnings; my $itemArea; my $itemPrice; my $itemId; my %thirdList; my $area; my $i; $itemArea = "0188"; $itemId = "0000007777"; $itemPrice = "40"; push @{ $thirdList{$itemArea} }, [ $itemArea, $itemId, $itemPrice ]; $itemArea = "0188"; $itemId = "0000009980"; $itemPrice = "41"; push @{ $thirdList{$itemArea} }, [ $itemArea, $itemId, $itemPrice ]; $itemArea = "0123"; $itemId = "0000008888"; $itemPrice = "50"; push @{ $thirdList{$itemArea} }, [ $itemArea, $itemId, $itemPrice ]; $itemArea = "0123"; $itemId = "0000009999"; $itemPrice = "51"; push @{ $thirdList{$itemArea} }, [ $itemArea, $itemId, $itemPrice ]; hardCodedPrint(%thirdList); sub hardCodedPrint { foreach $area ( keys %thirdList) { for ( $i=0; $i <= 1; $i++ ) { print "THIRD: "; print $thirdList{$area}[$i][0], " - "; print $thirdList{$area}[$i][1], " - "; print $thirdList{$area}[$i][2], "\n"; } } }
    hardCodedPrint() needs help. What I need is something like for (  $i=0; $i <= $# $thirdList{$area}; $i++  )  { But no matter what kind of casts and !@#$%^&* stuff I put in there (like $# @{ $thirdList{$area} }, I get a "$# is no longer supported" type of error - or worse. Any ideas? Thanks - Dave
jQuery issue with Dancer2
5 direct replies — Read more / Contribute
by stevieb
on Sep 22, 2016 at 19:20

    Right off the bat, I am positive this is a jQuery/Javascript issue, but before I ask questions on a forum that isn't Perlmonks, I'm hoping a Perl web monk could help.

    I've got a Dancer2 application that works well. I have a couple code snips without any context, but know for fact that the following returns to the jQuery call either 0 or 1:

    get '/get_aux/:aux' => sub { my $aux = params->{aux}; return _aux_state($aux); }; sub _aux_state { # maintains the auxillary state (on/off) my ($aux, $state) = @_; return $auxs->{$aux}{state} if ! defined $state; $auxs->{$aux}{state} = $state; return $state; }

    Now, in my javascript, I *know* that I receive the proper information. On page load finish, I set up a button (which is a glorified checkbox). It's 'checked' value should be a call back to the Perl code. I've augmented and hacked the jquery code so I can see what's happening. In this code, I call aux_state() to set things up. LINE 1, depicted in comments, alerts undefined. However, while I'm in the aux_state() function itself making the call back to Perl (LINE 2), I get an alert with the expected result:

    $(function(){ var state = aux_state('aux1'); alert(state); // LINE 1 $('#aux1').switchbutton({ checked: aux_state('aux1'), onChange: function(checked){ $.get(host +'/set_aux/aux1/'+ checked, function(state) +{ // ... }); } }); }); function aux_state(aux){ $.get(host +'/get_aux/' + aux, function(state){ alert(state); // LINE 2 return state; }); }

    I'm totally missing something with jQuery me thinks. Can anyone point me in the right direction? This is my first real attempt at writing async jQuery code. If not, I will proceed to ask on SO.

    I'm assuming my newbness in jquery is the issue here particularly with callbacks and returning things. If so, a pointer to a *good* doc would be handy. Even though I'm certain this isn't a Perl issue, I'd rather look at home before I go elsewhere (yep, I've searched online, but couldn't find anything conclusive perhaps because I don't know what to search for).



    update: I'm currently reading this.

Need script help
3 direct replies — Read more / Contribute
by jmckinzie
on Sep 22, 2016 at 13:05
    I have a command whose syntax is:  wspmvdata -s $srv -P sp:$src -t  \@$line -P tp: @ep1 @ep2 I can have as many @servers as I want as long as they fit in a command line (ie limitation) Can you help me figure out how to do this? This is what I have so far.
    #!/usr/bin/perl $pm=""; $srv=srv; $src="D:/Tivoli/bin/lcf_bundle.43100/bin/w32-ix86/inv/SCAN/"; $dst="C:/wansupp"; $file=binfile; $tmpfile="D:/Tivoli/custom/bin/binfile.txt"; $cmd="wspmvdata -s $srv -P sp:$src -t \@$line -P tp: $file"; ## this works but I want to shorten the list to a few test endpoints #@eplist=split(/\n/, `wlsendpts \ | grep End | grep -v tcp3 | gr +ep reg`); @eplist=(1_reg1, 2_reg1, 3_reg1); open(DATA, "<$tmpfile") or die "Can't open data"; @eplist = <DATA>; close (DATA); }
    I basically want to run the one command with @ep,@ep2,@ep3
How to parse a xml file using XML::DOM??
4 direct replies — Read more / Contribute
by ankit.tayal560
on Sep 22, 2016 at 05:15

    small part of my huge xml file is : """<signal sigid="3464" id="3490"> </signal>""" I want to get access to signal element. Input known is only sigid value i.e. 3464 . how can I do this with the help of XML::DOM? P.S. my xml file contains huge number of signal elements with different sigid values.

How to set pipe first and then use the forkmanager?
3 direct replies — Read more / Contribute
by mlin
on Sep 22, 2016 at 05:03
    While I'm trying to the ForkManager to do the parallel tasks. I find that I should pass the N data files to program A using a pipe. The form is like this:
    open $h, "| program_A" or die ...; foreach (@data_files) { print $h ...; print $h ...; ... } close($h);
    If I want to deal with these files parallelly, like using 4 processors, I think I must establish 4 pipes first(right?), then how to tell the perl to use these pipes automatically? I'm a little confused about the progress. Could you please tell me some schemes to solve this problem and give me some explanation? Thanks a lot! ----- complement: If while the program A runs, it usually print some information or warnings to the screen? Will it be a trouble for the forked processes? or I must throw the output of A, like:
    foreach (@data_files) { open $h, "| program_A 2>& /dev/null" or die ...; print $h ...; print $h ...; ... } close($h);
Limit Socket (throttle) to send specific ammount of packets every second
2 direct replies — Read more / Contribute
by Lucas Rey
on Sep 22, 2016 at 01:58
    Dear Community, I'm programming a simple script in perl that do the following:
    1) Open a socket to a specific server 2) Reads data line by line from a big file using a while loop 3) Send data using the open socket
    I don't report the whole code since it works perfect and could be too long. What I need to accomplish is send an ammount of packets every seconds. For example I would like to limit (throttle) to send 100 packets per second. What I need, is understand how (and if) I can implement this kind of mechanism, or simply an idea. The actual code looks like:
    Open Socket Open file containing data to send while # Read file line by line { Send data to Server }
    Thank you, Lucas.
Testing a library that accesses an Oracle Database
3 direct replies — Read more / Contribute
by docdurdee
on Sep 21, 2016 at 23:21
    Hello Monks, I'm writing tests for a program that accesses an Oracle database. When I run the tests directly or using prove, the tests work wonderfully. When I build the distribution (using Dist::Zilla) and run tests from the generated makefile, they fail: Could not connect to ... : install_driver(Oracle) failed: Can't load ... Library not loaded: @rpath/libclntsh.dylib.12.1 It must be an environment issue (I'm running OS X), but I have not been able to crack it via the usual endless googling. I think there may be some way to get the appropriate variables set via Dist::Zilla using the D::Z::P::MakeMaker::Awesome, but I shelved that effort in favor of hacking something that works at all to begin with. I tried setting the Oracle %ENV variables (dumped from my local environment where it works) within the problematic test using a BEGIN block, but still no luck...
    BEGIN { $ENV{ORACLE_HOME}="somepathto/oracle"; $ENV{DYLD_LIBRARY_PATH}="somepathto/oracle/lib"; }
    Any ideas? Thanks! UPDATE: I also tried unsetting the environment variables from within the test that works when I run it directly:
    The test still works!!!! I'm only able to make the test crash during the "make test" phase. This is curious...
compile error in perl script
2 direct replies — Read more / Contribute
by kks_perlnewbie
on Sep 21, 2016 at 14:08
    Hi I am new to perl and writing my first script I want to move *.txt files from one folder to another and input output folders are input , have wrote the script as below but getting errors. can anybody help here
    use Getopt::Std; $usemsg = "Usage: -i <input_folder> -w <working_dir> -o <o +utput_file> \n"; getopts('i:o:w:', \%options); if ((!exists $options{i}) || (!exists $options{o}) || (!exists $option +s{w}) ) { die $usemsg; } $inputfolder = $options{i}; $outputfile = $options{o}; $workingdir = $options{w}; #open the input directory to get a file list opendir(my $indir, $inputfolder) || die "Can't open input directory $i +nputfolder $! \n"; while (readdir $indir) { if ($_ =~ /txt$/){ my $tfn = "/".$_; move ($inputfolder.$tfn,$workingdir); } } # close the input directory closedir $indir;

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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 scrutinizing the Monastery: (7)
    As of 2016-09-26 05:32 GMT
    Find Nodes?
      Voting Booth?
      Extraterrestrials haven't visited the Earth yet because:

      Results (475 votes). Check out past polls.