Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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
How to Debug my perl script?
1 direct reply — Read more / Contribute
by ankit.tayal560
on Sep 28, 2016 at 06:36
    use strict; #use warnings; use Data::Dumper; use XML::DOM; my $parser=new XML::DOM::Parser; my $doc = $parser->parsefile('C:\perl\perl_tests\AirbgICIndPer2.xml')o +r die$!; my $root=$doc->getDocumentElement(); print("Enter the number of flags which needs to be removed...\n\n"); my $num2=<STDIN>; if($num2>0) { for(my $p=0;$p<$num2;$p++) { print("type the signal id for which flags need to be removed..\n\n +"); my $sig_id=<STDIN>; print("type the flag name which needs to be removed according to t +he instructions\n\n"); print("State on flag remove : type StateOn\n"); print("Indication Function remove : type IndicationFunctions\n"); print("First value flags remove : type FirstValueFlags\n"); print("timeout notification flag remove : type TimeoutFlags\n\n"); my $flag_to_be_modified=<STDIN>; print("processing geny file data\n"); ClearSignalAttribute($sig_id,$flag_to_be_modified); } sub ClearSignalAttribute($$) { my $sigid=$_[0]; my $attribute=$_[1]; my $sigattributes; my $sig; my @attributes; my @signals; my $signal_id; $sig=$root->getElementsByTagName("signal")->item(0); $signal_id=$sig->getAttribute("sigid"); print("the input signal id is : $sigid\n"); print("the other signal id is : $signal_id\n"); if($sigid==$signal_id) { print("signal id matched\n"); if($sig->getElementsByTagName("attributes")) { $sigattributes=$sig->getElementsByTagName("attribu +tes")->item(0); @attributes=$sigattributes->getElementsByTagName(" +attribute"); print("got the attributes\n"); } foreach my $attr(@attributes) { my $a=$attr->getAttribute("name"); print("into the attribute array: $a\n"); my $c="VIlRx".$attribute; print("the target is : $c\n"); #if($attr->getAttribute("name") eq "VIlRx" +.$attribute) if($a eq $c) { print("attribute matched:$a\n"); if(my $temp1=$attr->getElementsByTagNa +me("item")->item(0)) { print("got the item element\n"); if(my $temp2=$temp1->getElementsBy +TagName("data")->item(0)) { print("got the data element\ +n"); if ($temp1->getAttribute("used +")=='1') { $b=$temp1->getAttribute("used" +); print("Attribute->used : $b\n" +); $temp1->setAttribute("used","0 +"); $temp1->setAttribute("order"," +-1"); $temp2->setAttribute("flags"," +4"); my $w=$temp1->getAttribute("us +ed"); my $x=$temp1->getAttribute("or +der"); my $y=$temp2->getAttribute("fl +ags"); print("used : $w\n"); print("order : $x\n"); print("flags : $y\n"); } } } } } } } #$doc->setXMLDecl($doc->createXMLDecl('1.0','UTF-8')); #$doc->printToFile("C:/perl/perl_tests/AirbgICIndPer2.xml"); } XML FILE : <?xml version="1.0" encoding="UTF-8"?> <ecuconfig id="1" name="ECU: IPC_LS" FrameworkVersion="1.4.48.0" Compa +tibleVersion="1.4.0.0"> <signal sigid="3464" id="3490"> <attributes> <creator name="Il_Vector_Gm"> <attribute name="Il_Vector_Gm_StateOn" typeid="3" value="1"/> </creator> <creator name="VectorIL"> <attribute name="VIlRxSigType" typeid="4" flags="4" set="0" value=""/> <attribute name="VIlRxSet" typeid="3" flags="1"/> <attribute name="VIlRxGet" typeid="3" flags="1"/> <attribute name="VIlRxRDS" typeid="3" flags="4" set="0" value="0"> <sharing flags="7" value="0"/> <textinfos> <textinfo fromid="3"> This attribute has been disabled by IL_Vector component.</textinfo> </textinfos> </attribute> <attribute name="VIlRxTimeoutTime" typeid="2" flags="4" set="0" value= +"0"/> <attribute name="VIlRxIndicationFlags" typeid="12" set="0"> <item index="0" order="-1" used="0"> <data typeid="4" flags="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxIndicationFunctions" typeid="12" set="0"> <item index="0" order="0" used="1"> <data typeid="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxFirstValueFlags" typeid="12" set="0"> <item index="0" order="0" used="1"> <data typeid="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxDataChangedFlags" typeid="12" set="0"> <item index="0" order="-1" used="0"> <data typeid="4" flags="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxTimeoutFlags" typeid="12" set="0"> <item index="0" order="0" used="1"> <data typeid="4" value="AirbgICIndPer"/> </item> <item index="1" order="1" used="1"> <data typeid="4" value="AirbgICIndPer_1"/> </item> </attribute> <attribute name="VIlRxTimeoutFunctions" typeid="12" set="0"> <item index="0" order="-1" used="0"> <data typeid="4" flags="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxInitFunction" typeid="4" value=""/> <attribute name="VIlRxStartFunction" typeid="4" value=""/> <attribute name="VIlRxStopFunction" typeid="4" value=""/> <attribute name="VIlRxInitDefault" typeid="3" flags="1"/> <attribute name="VIlRxStartDefault" typeid="3" value="0"/> <attribute name="VIlRxStopDefault" typeid="3" value="0"/> <attribute name="VIlRxDefaultValue" typeid="4" flags="1"/> <attribute name="VIlRxTimeoutDefault" typeid="3" set="0" value="0"/> <attribute name="VIlRxTimeoutDefaultValue" typeid="4" flags="5"/> <attribute name="VIlRxTimeoutDynamicApi" typeid="3" flags="2" set="0" +value="0"> <sharing flags="7" value="0"/> </attribute> <attribute name="VIlRxRouting" typeid="3" flags="1"/> <attribute name="VIlRxTimeoutSupervisor" typeid="6" flags="4" orefid=" +1306"/> </creator> </attributes> <sources> <source srcid="19264"/> </sources> </signal> </ecuconfig>

    I've written the above script to modify the various attributes of "item" and "data" element. when I try to run this script it is not showing any error but not performing the required actions. it is not going inside the loop "if($a eq $c)" and simply printing all the names ignoring this loop . any suggestions about what is the bug in this script and how I can handle it?:

match the second column and print rest of the column in horizontal form
2 direct replies — Read more / Contribute
by Anonymous Monk
on Sep 28, 2016 at 05:20
    I have a file data.txt having three columns. I want to print the rest of the column if the second column is same.
    data.txt 1..1524 chromosomal replication initiator protein DnaA NC_017524 +.1 1..1524 chromosomal replication initiator protein DnaA NC_016768 +.1 1..1524 chromosomal replication initiator protein DnaA NC_009565 +.1 1000808..1002415 oxidoreductase NC_009565.1 1000808..1002415 oxidoreductase NC_017528.1 1002441..1002704 hypothetical protein NC_016934.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_017523.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_021194.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_018143.2 1002812..1003792 peptidoglycan-binding protein ArfA NC_020089.1
    I want the output as:
    1..1524 chromosomal replication initiator protein DnaA NC_017524 +.1 NC_016768.1 NC_009565.1 1000808..1002415 oxidoreductase NC_009565.1 NC_017528.1 1002441..1002704 hypothetical protein NC_016934.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_017523.1 + NC_021194.1 NC_018143.2 NC_020089.1
    I will be thankful for any help
Can't locate module IniReader in @INC
2 direct replies — Read more / Contribute
by zjj19910
on Sep 28, 2016 at 04:06
    I searched it on metacpan and other websites as well but just couldn't find a module named exactly IniReader. Note: I run Trinotate and it uses IniReader module.
How to modify an XML file using XML::DOM
3 direct replies — Read more / Contribute
by ankit.tayal560
on Sep 28, 2016 at 01:20

    I've written this code but the modifications are not reflecting in the xml file.am I missing something important in the code? confused about using perl in xml! would be glad if someone can help and explain in a detailed manner how to perform this task? I am getting output as Joey 67890

    use strict; use warnings; use Data::Dumper; use XML::DOM; my $parser=new XML::DOM::Parser; my $doc=$parser->parsefile('C:\perl\perl_tests\xmlin.xml') or die$!; my $root=$doc->getDocumentElement(); my @address=$root->getElementsByTagName("address"); foreach my $address(@address) { if($address->getAttribute("name") eq "tayal") { if($address->getAttribute("id")=='70889') { $address->setAttribute("name","Joey"); $address->setAttribute("id","67890"); my $temp1=$address->getAttribute("name"); my $temp2=$address->getAttribute("id"); print("$temp1\t$temp2\n\n"); } } } XML FILE : <config logdir="var/log/foo/" debugfile="tmp/foo.debug"> <server name ="sahara" osname ="solaris" osversion="2.6"> <address name="ankit" id="70888"/> <address name="tayal" id="70889"/> </server> <server name="gobi" osname="irix" osversion="6.5"> <address name="anshul" id="70689"/> </server> <server name="kalahari" osname="linus" osversion="2.0.34"> <address name="raghu" id="45678"/> <address name="lucky" id="67895"/> </server> </config>
[(way)OT] Formula for volume of a circular lens with an elliptical profile?
2 direct replies — Read more / Contribute
by BrowserUk
on Sep 27, 2016 at 19:17

    Usual reasons: a) I've looked in all the usual places; b) we usually get quicker, better answers here than other places. (If it mitigates, the calculation will be performed by a Perl script.)

    Given (R)adius and (T)hickness (major and minor axes), the foci are at ((R/2)2 - (T/2)2)-2, and the area is πRT.

    Is the volume as simple as: π2RT?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
using Getopt::Long
2 direct replies — Read more / Contribute
by v15
on Sep 27, 2016 at 15:41
    Hi Everyone, I have a file something like this:
    chr10 180833 225933 1 1 0 1 0 16 chr10 181144 225933 1 1 0 2 0 13 chr10 181243 225933 1 1 0 4 0 32 chr10 181500 225933 1 1 0 5 0 34 chr10 196199 196457 1 1 0 1 0 31 chr10 226069 243850 1 1 0 1 0 25 chr10 226069 255828 1 1 0 32 0 37 chr10 255989 267134 1 1 0 24 0 33 chr10 255989 282777 1 1 0 13 0 38 chr10 267297 282777 1 1 0 33 0 38
    I want to write a script in perl where I can print out those lines in which column 7 is greater than 10. my code is as follows:
    while(<>){ chomp; my @s = split /\t/,$_; my $count = $s[6]; if($count > 10){ print $_,"\n"; } }

    What i want to do is use Getopt::Long module and make a flag --unique so that I can feed any value to that flag let's say 2 or 4 or 10 etc and it prints the line fulfilling the condition. How can I do that?

    Thanks Varun
Win32 OLE Word Add Password?
1 direct reply — Read more / Contribute
by cormanaz
on Sep 27, 2016 at 12:53
    Good day bros. Does anyone know how to add a password to a Word doc using Win32 OLE?
Issues with substr and substituting
2 direct replies — Read more / Contribute
by lecb
on Sep 27, 2016 at 12:01

    Dear Monks, Please may I kindly ask for some assistance please? Please be gentle however.. I am not an expert coder and I am also incredible inefficient, but for now I have to code in a way that makes logical sense to me. I have tried my best for 5 days with this and now I'm at the point where I need some external help...

    The input file is commented in the code since I can't upload it for you. Essentially what I am trying to do is change the last column of the input (a 9 letter sequence) by changing each letter to an alternative of 3 letters AGCT, then moving onto the next letter in the sequence.

    I.e. for each character of the last column, if it matches A, then switch to G then print new line, switch to T then print new line, switch to C then print new line (whilst remaining sequence stays same).

    Example 1: for >chr1 67093601 67093610 CTACAGGAA -> switch to GTACAGGAA, TTACAGGAA, ATACAGGAA.

    Then: CTACAGGAA -> switch to CAACAGGAA, CGACAGGAA, CCACAGGAA etc.

    Therefore, for each sequence there should be 27 new sequences.

    From looking at the output, I think the issue lies in the "$sequence =~ s/$test/C/;" bit of code, but I don't know how to fix it... the $j seems to count along the string as I'd like it to, but sometimes the wrong letter in the sequence in changed, and sometimes it is not!

    If anyone can help me, I will be very, very grateful.

    BW LECB

    #!/usr/bin/perl use strict; use Data::Dumper; use Storable; ## 5_prime_ref.fasta => # >chr1 67093601 67093610 CTACAGGAA # >chr1 67095418 67095427 TTTCAGAAA # >chr1 67096318 67096327 TTTCAGCTC # >chr1 67115461 67115470 TTCCAGGCA # >chr1 67125906 67125915 CTGCAGATA # >chr1 67127254 67127263 AAATAGGAA # >chr1 67131224 67131233 TAATAGATT # >chr1 67093601 67093610 CTACAGGAA # >chr1 67096318 67096327 TTTCAGCTC # >chr1 67103379 67103388 GTTTAGATG # >chr1 67111641 67111650 CTTTAGAGC # >chr1 67115461 67115470 TTCCAGGCA # >chr1 67125906 67125915 CTGCAGATA # >chr1 67127254 67127263 AAATAGGAA # >chr1 67131224 67131233 TAATAGATT # >chr1 67093601 67093610 CTACAGGAA # >chr1 67096318 67096327 TTTCAGCTC # >chr1 67103379 67103388 GTTTAGATG # >chr1 67111641 67111650 CTTTAGAGC # >chr1 67113753 67113762 ATATAGTGA # >chr1 201324579 201324588 GGGTAAGGT open my $fasta5, '<', '5_prime_ref.fasta'; chomp (my @fasta5 = <$fasta5>); close $fasta5; my ($altsequence1, $altsequence2, $altsequence3, @newfasta5, @newfasta +3, $sequence, @splity, $test, $j, $genomicposition, $ref, $alt1, $alt +2, $alt3, $refsequence); ## for 5 prime ## >chr1 201324579 201324588 GGGTAAGGT foreach my $line (@fasta5) { ## need to iterate 9 times through j... $j = 0; while ($j < 9) { @splity = split ("\t", $line); my $ref = $splity[3]; $sequence = $splity[3]; $refsequence = $splity[3]; $genomicposition = $splity[1]; $genomicposition = $genomicposition + 1; #first nucleotide is coun +ted as first column + 1, not as the left boundary $splity[0] = ">".$splity[0]; ##if ($character $j in sequence =~ matches A) { if (substr ($sequence, $j, 1) =~ m/A/) { $ref = "A"; $genomicposition = $genomicposition + $j; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/C/; $altsequence1 = $sequence; $alt1 = "C"; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/G/; $altsequence2 = $sequence; $alt2 = "G"; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/T/; $altsequence3 = $sequence; $alt3 = "T"; } elsif (substr ($sequence, $j, 1) =~ m/C/) { $test = substr ($sequence, $j, 1); $ref = "C"; $genomicposition = $genomicposition + $j; $sequence =~ s/$test/A/; $altsequence1 = $sequence; $alt1 = "A"; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/G/; $altsequence2 = $sequence; $alt2 = "G"; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/T/; $altsequence3 = $sequence; $alt3 = "T"; } elsif (substr ($sequence, $j, 1) =~ m/T/) { $test = substr ($sequence, $j, 1); $ref = "T"; $genomicposition = $genomicposition + $j; $sequence =~ s/$test/A/; $altsequence1 = $sequence; $alt1 = "A"; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/G/; $altsequence2 = $sequence; $alt2 = "G"; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/C/; $altsequence3 = $sequence; $alt3 = "C"; } else { $ref = "G"; $genomicposition = $genomicposition + $j; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/A/; $altsequence1 = $sequence; $alt1 = "A"; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/T/; $altsequence2 = $sequence; $alt2 = "T"; $test = substr ($sequence, $j, 1); $sequence =~ s/$test/C/; $altsequence3 = $sequence; $alt3 = "C"; } ## print the new 3 lines my $newfasta5alt1 = join ("\t", $refsequence, $splity[0], $splity[ +1], $splity[2], $altsequence1, $ref, $alt1, $genomicposition); my $newfasta5alt2 = join ("\t", $refsequence, $splity[0], $splity[ +1], $splity[2], $altsequence2, $ref, $alt2, $genomicposition); my $newfasta5alt3 = join ("\t", $refsequence, $splity[0], $splity[ +1], $splity[2], $altsequence3, $ref, $alt3, $genomicposition); my $newfasta5 = join ("\n", $newfasta5alt1, $altsequence1, $newfas +ta5alt2, $altsequence2, $newfasta5alt3, $altsequence3); push (@newfasta5, $newfasta5); $j++;} next; } print Dumper @newfasta5;
Perl script to run for x hours
4 direct replies — Read more / Contribute
by t-rex
on Sep 27, 2016 at 06:41

    Hello Monks,

    In my script i give user a parameter where he mentions he wants to run this script for x number of hours, how should i implement this? I read online , one way could be using SIGALRM and writing handler for this so that when this is achieved I stop the script,

    please suggest other efficient ways if there exist, thanks

error : can't locate object method "getAttribute" via package XML::DOM::NodeList
2 direct replies — Read more / Contribute
by ankit.tayal560
on Sep 27, 2016 at 04:02
    use strict; use warnings; use Data::Dumper; use XML::DOM; my $parser=new XML::DOM::Parser; my $doc=$parser->parsefile('C:\perl\perl_tests\xmlin.xml') or die$!; my $config=$doc->getElementsByTagName("config"); my $config_attr=$config->getAttribute("logdir"); print("$config_attr");

    XML file :<config logdir="var/log/foo/" debugfile="tmp/foo.debug"> <server name ="sahara" osname ="solaris" osversion="2.6"> <address>10.0.0.101</address> <address>10.0.1.101</address>Text </server> <server name="gobi" osname="irix" osversion="6.5"> <address>10.0.0.102</address>text1 </server> <server name="kalahari" osname="linus" osversion="2.0.34"> <address>10.0.0.103</address> <address>10.0.1.103</address>Text2 </server> </config> when I try to run this script I get an error saying : can't locate object method "getAttribute" via package "XML::DOM::NodeList" at C:\perl\perl_tests\xmlin.pl line 10. what is the problem with my script?


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!
  • 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?
    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 cooling their heels in the Monastery: (9)
    As of 2016-09-28 14:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Extraterrestrials haven't visited the Earth yet because:







      Results (532 votes). Check out past polls.