Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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
Perl: How to convert db2 utf8 czech special character to latex format
1 direct reply — Read more / Contribute
by zimso
on Sep 28, 2016 at 10:57
    Hello,

    please maybe someone can help me :

    - I have a DB2 database which is in codeset UTF-8 and codepage 1208

    - I have a field "lastname" which has some names which contain east european special character ( and // s with caron or a with acute)

    - my environment on the shell is LANG=de_DE.utf8

    - I read the DB field with DBI module into Perl and want to convert the name to latex format for printing, but it doesn't work for the "s with caron"

    (a with a acute) (Unicode-Nummer: U+00E1 HTML-Code: á) ---->wanted goal: Latex format \'{a}

    (s with caron) (Unicode-Nummer: U+0161 HTML-Code: š) ---->wanted goal: Latex format \v{s}

    I don't manage to convert the "s" character:

    $tmp has ' '

    I try a print TeX::Encode::encode('latex',$tmp); It gives : \'a?

    \'a is correct "?" for the "" is not

    When I directly save the field to a file and look with a hexeditor on it it says: "e1 1a"

    e1 is correct "1a" isn't (according to latin-2 it should be "b9")

    Hmmm... Can someone please help me to manage to bring these east european names from a utf8 db to a universal latex format for printing ?

    Many Many Thanks !!!!!!

    Tina

Finding Nearly Identical Sets
1 direct reply — Read more / Contribute
by Limbic~Region
on Sep 28, 2016 at 10:51
    All,
    This isn't so much a perl question as an algorithm question but the solution will be coded in perl (at least partially).

    The program will be processing millions of messages that contain a set of 9 digits where each digit may have a value of 1-9. For instance, it may contain (1, 7, 3, 3, 9, 5, 6, 1, 2). It is critical that all messages that contain the same set need to be stored together.

    Unfortunately, the set may contain an error (think typo). If a set doesn't match any previously seen sets exactly, the program needs to determine if this should be a new set or if it belongs to a previous set. Assume that I have a perfect way of doing this if I have two messages side by side, what I am looking for is a fast/cheap way to identify candidate sets.

    In other words, I can't compare each set to every previous set. What I want to be able to do is very quickly/cheaply identify some candidates that are worth the time to do an expensive message to message compare. Here are the types of things I want to allow for:

    • Any change to the order (1,2,3,4,5,6,7,8,9 instead of 9,8,7,6,5,4,3,2,1) AND/OR 1 of the following:
    • Exactly 1 insertion (10 digits instead of 9) OR
    • Exactly 1 deletion (8 digits instead of 9) OR
    • Exactly 1 transformation (7 instead of a 5)

    If I were just going with the first one, it would be simple. Sort/concatenate the list and perform a hash lookup.

    I am sick with a pretty bad head cold so I am going to assume I have done a poor job of explaining. I apologize in advance. Here are some of the ideas I have came up with that I don't think will work:

    • Using a range of the product of the set
    • Using a range for the average and deviation of the set
    • Using a range for the "distance" to another 3rd hardcoded set

    Fast and cheap but without too many false positives - ideas?

    Cheers - L~R

Parsing NE Command Line Arguments
1 direct reply — Read more / Contribute
by Scully4Ever
on Sep 28, 2016 at 10:45

    I wrote a script that uses Getopt::Long to get the command line arguments. Is there a way to allow the user to use != in addition to "= so the user could for example request data not equal to year 2016 or data equal to year 2016?

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?

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 musing on the Monastery: (9)
    As of 2016-09-28 16:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Extraterrestrials haven't visited the Earth yet because:







      Results (533 votes). Check out past polls.