Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Extracting Unique elements

by wind (Priest)
on Jun 14, 2011 at 23:49 UTC ( [id://909671]=note: print w/replies, xml ) Need Help??


in reply to Extracting Unique elements

Replies are listed 'Best First'.
Re^2: Extracting Unique elements
by smandape1 (Acolyte) on Jun 16, 2011 at 16:50 UTC

    I tried, but I am unable to use them directly. The thing is the data 'title' gets extracted twice for more than one users because of the loop. I want to restrict the loop to extract elements like title, PMID and list of authors only once. And I want to do it while I am extracting it. It seems that I can remove the duplicates later but, it all messes up. Because there are some users and tags that are duplicates too, but I want them. Can you help please.

      Just use a %seen hash like demonstrated in the resource I linked you to. It will enable you to filter out any duplicates as you go just as easily as removing duplicates after the fact.

        Thanks Wind. I really appreciate your help. Okay, while I was playing around with perl code, I found something interesting. Probably you can explain it to me in better way. I was trying to use get() for a webquery. Something like below:

        $url = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=$d +b1&id=$query&retmode=text&rettype=abstract"; $data = get($url);

        when I put $url in single quotes it doesn't work with the $db and $query but if I put it in double quotes it works. Why is it so, what is the relation between quotes and scalar quantity? It would be really nice if you can explain this to me. Thank you, Sammed

        Hey Thanks a lot. I got it. I greatly appreciate your help. I have another small issue. when I get the array of something I extract, I try to print them using the code

        if (ref($bar) eq "ARRAY") { foreach my $q (@$bar){ print FH $q ,","; } } else { print FH $bar; }

        But, this doesn't seem to be of help. I want to do something that if its an array separate them by ',' else just print the individual without ','. But when I use the above code it also prints the single element with a ',' and in an array it gives ',' after the last element. I know how to solve the same issue in XSLT its something like

        <xsl:test if position() != last()> <xsl:value-of select="."/>; </xsl:test> <xsl:test if position() = last()> <xsl:value-of select="."/> </xsl:test>

        Thus everything is separated by ';' except for the last element and if its only a single element then it gets printed as it is. Can I do something same in perl, can you please help. Thank you, Sammed

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://909671]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-23 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found