Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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
File reade and recreate
1 direct reply — Read more / Contribute
by adriang
on Aug 20, 2014 at 03:48

    Hi all,

    I want to create a counter using a file but this don't work

    #!/usr/bin/perl use warnings; use strict; use Carp; open(my $count_file,"+<","count.txt") or croak "cant open"; my $count=<$count_file>; $count++; print $count_file $count; print $count; __END__

    only this work:

    #!/usr/bin/perl use warnings; use strict; use Carp; open(my $count_file,"<","count.txt") or croak "cant open"; my $count=<$count_file>; $count++; open($count_file,">","count.txt") or croak "cant open"; print $count_file $count; print $count; __END__

    I want to use OPEN only once.

    Thanks in advace, Adrian.

Concatenating Array elements
5 direct replies — Read more / Contribute
by lmtaylor
on Aug 19, 2014 at 16:23

    If I am to concatenate two elements of an array, will the index numbers assigned to the array elements update? In other words, if I were to run this code:

    @array = (1..10);

    $array[7] = $array[7] . $array[8];

    My array now has the following elements:

    1

    2

    3

    4

    5

    6

    78

    9

    10

    Is the index of 9 still $array[9]? Or has it been bumped up to $array[8] since the number that was in $array[8] has been concatenated with $array[7]?

    I've tried searching for this online, but couldn't find anything...maybe I'm using incorrect terminology?

    Thanks a lot!

    - Lisa

parsing the Windows directories
2 direct replies — Read more / Contribute
by g_speran
on Aug 19, 2014 at 16:22

    Hello All,

    I am trying to write a script that would parse thru a windows directory supplied and return the object type encountered (File, Directory, Link, etc), size, atime, ctime, and mtime.

    I located some code on the internet that kinda works, but when it gets to a windows link/shortcut (.lnk), the script fails with:

    Use of uninitialized value in bitwise and (&) at C:\temp\showmodes.pl line 5.

    Can't stat() 'C:\Users\admin\Favorites\MSN Websites\MSN Autos'

    Any thoughts on how to parse thru all object type and it return the appropriate information?

    #!/usr/bin/perl use strict; use warnings; my $name = shift or die "Usage: $0 file|directory\n"; my $mode = ( ( lstat($name) )[2] ) & 07777 or die "Can't stat() '$name +'\n"; printf "%s %04o %s\n", ( -f _ ) ? 'f' : ( -l _ ) ? 'l' : ( -d _ ) ? 'd' : ( -b _ ) ? 'b' : ( -c _ ) ? 'c' : ( -p _ ) ? 'p' : ( -S _ ) ? 's' : '?', $mode, $name; 1;

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.
could not get exec and sytem to work
4 direct replies — Read more / Contribute
by mnam
on Aug 19, 2014 at 14:47
    #!/usr/bin/perl -w use strict; use warnings; my $home='~/bin/MIReNA-2.0'; exec("cd $home"); exec("./MIReNA.sh");
    I am trying to run a shell script MIReNA.sh from within perl. could not run properly.
Clustering/classifying recommendations
1 direct reply — Read more / Contribute
by f77coder
on Aug 19, 2014 at 12:30

    Hello

    I'm interested in recommendations for clustering with attributes of being fast over lightweight/small. So I'd prefer loops over one-liners if the loop can be executed faster. Now I'm looking through the large list of various CPAN archives (AI, Bayes, Cluster, etc) and would like narrow down the search. I don't mind getting the source code and having to hack if doesn't quite match what I need to do rather than having an expectation of something work as is.

    The input data is a mixture of integers and strings, all categorical data. I'd like to look at each data line as an array and do vector processing, think of it as a 1d image processing problem, how many pixels are different.

    For example,

    line1=> cat1=123, cat2=92, cat3=5, cat4='0xffa411', cat5='0x221133', cat6='0xa291f1'

    line2=> cat1=3, cat2=92, cat3=5, cat4='0xaf1401', cat5='0xaaffcc', cat6='0xa23af1'

    I'd like to create a distance measurement based only on the number of categories that are different, in this case, the distance map would be (cat2,cat3,4). There will probably be a weighting function applied to this metric as well.

    Once the training is complete then for a new line make a prediction with the classify/cluster.

    Thanks

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
mod_perl - ghost values
3 direct replies — Read more / Contribute
by rpike
on Aug 19, 2014 at 11:52
    I'm currently running a cgi Perl application that has worked fine on IIS. We moved the application over to a Linux server and set up mod_perl on it. On the Linux server we're getting some strange results. When we click on a link for mugs (let's say for simplicity sake) we get 5 mugs. If we go to a page for shirts we get 12 t-shirts show up. If we go back to the mugs page it may show the 5 mugs but if you do a refresh (one, twice, or a few times) we'll end up getting 5 mugs displayed along with 3-6 t-shirts from the old link. What could possibly cause values like this to stick around but still get the correct items as well? I'm hoping some suggestions can be thrown out without having to post the lengthy code. Any help would be appreciated.
Calc Help
2 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 19, 2014 at 11:20

    Write a program called calculate.pl which will operate as a primitive calculator operating on a single number (the 'accumulator') whose value may be modified by user commands. The program should meet the following requirements:

    When called with arguments, interprets them as names of files containing commands.

    When called without arguments, reads commands from standard input. You may find it easy or at least entertaining to run the program in this mode.

    Commands are lines that match one of the following patterns:

    • EQUALS
    • CLEAR
    • PLUS number
    • MINUS number
    • TIMES number
    • OVER number

    The intended effects of those commands can be seen in the following capture of program interaction. User input is EQUALS, CLEAR, PLUS, OVER, TIMES, MINUS. The accumulator starts out undefined.

    calculate.pl dialog $ ./calculate.pl EQUALS (undefined) OK CLEAR OK EQUALS = 0 OK PLUS 42 OK EQUALS = 42 OK OVER 7 OK TIMES 3 OK MINUS 3 OK EQUALS = 15 OK explode Invalid statement

    You can assume that there is exactly one space between the operator and the number in valid commands. You do not have to trap division by zero or warnings about operating on an undefined accumulator.

    Use subroutines to keep the length of the main program and each of the subroutines below a standard screen (24 lines) at one statement per line.

    Output a prompt string "> " before each input, like so: calculate.pl dialog

    $ ./calculate.pl > EQUALS (undefined) OK > CLEAR OK > EQUALS = 0 OK > PLUS 42 OK > EQUALS = 42 OK > OVER 7 OK > TIMES 3 OK > MINUS 3 OK > EQUALS = 15 OK > explode Invalid statement >

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This is what I have so far:

    #!/usr/bin/perl use strict; use warnings; my $total; print "> "; while(my $line = <>){ chomp $line; my ($cmd, $num) = split " ", $line, 2; process($cmd,$num,$total); print "OK\n\>"; } sub process{ my($cmd,$num,$total) = @_; print "COMMAND: $cmd, VALUE: $num, TOTAL: $total \n"; }

    I'm not planning on proceeding with learning much more Perl, however, I would just like to see how this project can be accomplished for piece of mind. Any help would be greatly appreciated!

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.


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 studying the Monastery: (11)
    As of 2014-08-20 09:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (108 votes), past polls