Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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
Perl Script
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 17, 2015 at 05:04
    Hello all,I am perl beginner.i am writing a perl script.In which I am calling one file inside that file further more 4 files.I want to open that 4 files and grep some specific string.What should i do?I tried this using array but i want to do it using hash of hash.Please help.
Making commond for large number of files
6 direct replies — Read more / Contribute
by acrobat118
on Apr 17, 2015 at 03:50

    Dear fellows. I am new user of perl. I need your help in a problem. I have 200 files with extension .log. Each file contains alot of text and information. But I am only concern with a term in each file as SCF Done = some value of energy. The value of energy is different in each file. I want to make a proscript with perl in which I want: 1. Find the file among 200 files which contains lowest value of energy I.e. lowest value of SCF Done. 2. From a column say column $3 of that file found in step 1, individually substract the column $3 of all remaining 199 files. 3. Report the result of step 2 for each file separately in a single column in a single text file. Please help me as I have been struggling for a week. Anxiously waiting your reply.

Using . in variable name
4 direct replies — Read more / Contribute
by manpreet333
on Apr 17, 2015 at 02:50
    Hello monks,

    I just joined this portal and this is my first question and it's kind of stupid. I have this situation where I have to use . (the concatenation operator) in a variable identifier. I tried escaping, but that didn't work.

    This variable is being accessed by another script and I cannot change the name there.

    Could anybody provide a workaround to having the "." in the variable name? I need it to be something like $app1.svr

Two files, if the first line and the first column are the same, print this line, the second line, the third line,the fourth line.
3 direct replies — Read more / Contribute
by yueli
on Apr 16, 2015 at 23:22

    Hi Two files, if the first line and the first column are the same, print this line, the second line, the third line,the fourth line. What's wrong with me?

    01.txt >SR1.2 >SR1.3 02.txt >SR1.1 HWI-ST ATGCTGCT TCGTCGAT CTGATCAGCTAC >SR1.2 HWI-ST0 TTTTGCTGCT TCGTTGGG CTTTATCAGCTAC >SR1.3 HWI-ST0787 GGGGGCTGCT AATCGTCGAT AACTGATCAGCTAC result >SR1.2 HWI-ST0 TTTTGCTGCT TCGTTGGG CTTTATCAGCTAC >SR1.3 HWI-ST0787 GGGGGCTGCT AATCGTCGAT AACTGATCAGCTAC #!/usr/bin/perl -w use strict; open(IN1,"01.txt") || die "Cannot open this file"; my @lines1 = <IN1>; open(IN2,"02.txt") || die "Cannot open this file"; my @lines2 = <IN2>; my $i=0; open(OUT,">out01") || die "Cannot open this file"; for my $item1(@lines1){ chomp $item1; my@tmp1=split(/\s+/, $item1); for my $item2(@lines2){ chomp $item2; my @tmp2=split(/\s+/, $item2); if ($tmp1[0] eq $tmp2[0]){ print OUT $lines2[$i],"\n",$lines2[$i+1],$line +s2[$i+2],$lines2[$i+3]; last; } $i++; } print OUT "\n"; } close(IN1); close(IN2); close(OUT);
    Thanks in advance!
Remove Duplicates Multidimensional Array?
2 direct replies — Read more / Contribute
by johnfl68
on Apr 16, 2015 at 22:00

    Hello, and again many thanks to the many helpful people here.

    Any suggestions on removing duplicates in a Multidimensional Array/Hash (sorry, I always get the array/hash thing confused, I think it's the dyslexia)?

    There are some entries that are "almost" identical, and I want to delete the duplicates

    $VAR1 = { 'vehicalData' => [ { 'manufacturer' => 'Kia', 'model' => 'Rio', 'year' => '2001', 'mileage' => '130256', 'color' => 'Metallic Blue' }, { 'color' => 'Lt Blue', 'mileage' => '130242', 'year' => '2001', 'model' => 'Rio', 'manufacturer' => 'Kia' }, { 'model' => 'Focus', 'manufacturer' => 'Ford', 'year' => '2003', 'color' => 'Red', 'mileage' => '100684' } ] };

    I kind of understand using unique, but for a single array. I'm not really sure where to begin with this.

    There are more than 3 entries, but this gives you an example. The first 2 entries are the same car, just 2 separate entries that made it in to the database, with slightly different information. I want to get rid of one of the entries.

    I'm just not sure where to start on this one, so any pointers in the right direction would be greatly appreciated.

    Thanks again!

Any tips on passing bash variables as arguments to a perl script (that contain spaces and/or non-ascii characters)
4 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 16, 2015 at 19:19
    Hi wise ones. I'm having a problem with interpolation with one of my perl scripts. I am pretty sure the issue is the shell, and not my script, but here is the scenario:

    One of our tools (HP Open view) -- can send output of monitoring alerts into various pieces via linux/unix string variables (like $OPC_MSG_TEXT) -- which we use primarily in bash scripts. This is handy, since you can just slurp them in and call them via $1, $2, $3, $4, etc.

    Problem is I want to use perl for some more advanced parsing. Several of these variables contain spaces, line returns, etc. If I try to pass the variables directly to perl as arguments, (such as ovo-test.pl $OPC_MSG_TEXT), it does't store all the contents of $OPC_MSG_TEXT into $ARGV[0] -- it splits the contents based on spaces..my understanding is that this is default linux/unix behavior?

    Anyway -- I am trying to find a way to slurp these bash variables into my perl script, and keep all original white spacing, etc. Not sure how to go about this. I'd really like to minimize the usage of bash.

    Any suggestions? I really don't want to use a bash script with embedded perl if at all possible.

format file
2 direct replies — Read more / Contribute
by bishop2001
on Apr 16, 2015 at 17:51
    hi i have a file which contains the following:
    11,1428969620,bill<br> 42,1428969618,bob<br> 34,1428969617,joe<br> 55,1428969613,bill<br> 22,1428969614,bob<br>
    what id like is:
    bill bob joe 1428969620 11 1428969618 42 1428969617 34 1428969613 55 1428969614 22
    i have a basic perl ability, but im not sure where to start on this. Thanks

    Content restored and Code tags added by GrandFather

Problem with storing values
2 direct replies — Read more / Contribute
by mavericknik
on Apr 16, 2015 at 14:37
    Hello people, Im pretty new to perl, just learning right now. I'm looking to replace some cells in a verilog file using the verilog-perl module. My question is this: The verilog perl module has a function called "->dump_drivers". So basically when I do:
    $netdrivers = ($pin->net)->dump_drivers;
    The output I see on the screen is:
    Net:in2 Port: in2 in Pin: U1.IN2 in Pin: U2.IN2 in
    What I am trying to so is this :
    $netdrivers = ($pin->net)->dump_drivers; my @netdrivers_split = split(/\n/,$netdrivers); foreach my $val (@netdrivers_split) { #some code }
    What I want it to do is save
    Net:in2 Port: in2 in Pin: U1.IN2 in Pin: U2.IN2 in
    Then split it into an array using the newline delimiter so I can use the individual values. But when I do
    $netdrivers = ($pin->net)->dump_drivers; my @netdrivers_split = split(/\n/,$netdrivers); print @netdrivers_split;
    I get:
    Net:in2 Port: in2 in Pin: U1.IN2 in Pin: U2.IN2 in 0 but true
    Why is the value in "@netdrivers_split" "0 but true"? Is this the right way to do it?
Populating a hash-ref from multiple arrays with slice?
4 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 16, 2015 at 13:33
    Hi perl monks. I am stumped with this one.

    I have several arrays that I want to slice into a single hash ref. Any tips? I read a bit about creating a hash slice from 2 arrays, but can't figure out the syntax for creating a hash ref slice from multiple arrays.

    For example (excuse grammatical errors -- this is more pseudo code than anything):

    $hash_ref; @array1 = "some_unique_key1 some_unique_key2 some_unique_key3"; @array2 = "meta_data_1 metadata_2 metadat_3"; @array3 = "submitted_date1 submitted_date2 submitted_date3";

    The hash ref would have a structure like:

    $some_uniquekey1 --> 'Metadata' --> $meta_data1 = '1' --> 'Submitted Date' --> $subitted_date1 = '1' $some_uniquekey2 ... etc $some_uniquekey3 ... etc

    Basically the arrays value indices all correspond to each other -- I just want to merge them all into an accessible table.

    Any tips or slaps up the side of my head appreciated!

Changing a variable which is a value of a hash
5 direct replies — Read more / Contribute
by benedicth
on Apr 16, 2015 at 11:40
    Suppose there is a variable which is then declared a value of a hash. I then want to change $test to the content of $change but not change the hash reference. The result should be $test = 'change' while $hash{t} stays $test.
    $test = 'test'; %hash = ( t => $test); $change = 'changed'; $hash{t} = $change; #I just want to change $test to 'changed' not $hash{t} to $change
    I understand this is wrong but can't find an explanation for using variables as hash values. thanks for your help pros.

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 drinking their drinks and smoking their pipes about the Monastery: (4)
    As of 2015-04-18 05:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Who makes your decisions?







      Results (350 votes), past polls