Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

creating a LINK

by lucifersmith (Initiate)
on Apr 24, 2014 at 18:56 UTC ( #1083670=perlquestion: print w/replies, xml ) Need Help??

lucifersmith has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: hey monks
by rjt (Curate) on Apr 24, 2014 at 19:10 UTC

    It's not exactly clear what you're asking. First, please see How do I post a question effectively? and, "hey monks": How do I compose an effective node title?

    In general terms, however, there are numerous ways to do what you ask. Consider this example:

    my @arr = ( { filename => 'foo.txt', time => time(), filetype => 'furry', }, { filename => 'readme', time => time(), filetype => 'blue' }, );

    Now @arr contains references to two hashes, each containing the fields you specified (in lowercase, you can use uppercase if you really want to, but most Perl code wouldn't).

    To pull together all files of a specific filetype, you can use this sort of construct:

    my @blue_files = grep { $_->{filetype} eq 'blue' } @arr;

    And to print the filenames from that:

    print "$_->{filename}\n" for @blue_files;

    Hopefully these very simple examples will be relevant to you, and will help you grasp some of the basics. Please do make good use of perlintro and the other resources here.

    use strict; use warnings; omitted for brevity.
Re: hey monks
by davido (Cardinal) on Apr 24, 2014 at 19:25 UTC

    We cannot provide a thorough and accurate answer (short of getting lucky in guessing) without knowing more about your data set. Why don't you post the contents of, say, five of the elements in @arr, rather than partially describing the field names.

    Be sure to wrap this sample data in code tags so that we can see if there are useful patterns such as fixed-width field sizes.

    Also explain how a person looking at the data should differentiate between the fields; are they separated by white space? Are they separated by commas? Are delimiters allowed within the fields too? If so, how does escaping work? Does this data format have a name that we might recognize, or was it produced by a commonly known source (which saves you a little work in describing it)?

    We don't know what you're working with unless you tell us, and if we don't know what you're working with, we don't know how to show you to work with it.


    Dave

Re: hey monks
by mr_mischief (Monsignor) on Apr 24, 2014 at 20:33 UTC

    I can't be sure of your data since you didn't provide it. Is the code to handle it most like #1, #2, or #3 below?

    my @arr1; while ( <> ) { my @arr = split ',', $_; ( push @arr1, $arr[0] ) if $arr[2] eq 'particular'; }
    my @arr1 = grep { @{$_}[2] =~ /particular/ } @arr;
    my @arr1 = grep { %{$_}{'FILETYPE'} eq 'particular' } @arr;

    If you can't answer that, then you'll need to provide your input and desired output.

    Problems have solutions. If you can't define a desired state and explain how it is different from the current state then you don't have a problem. You have a gripe. Gripes don't have solutions other than turning them into problems. Note that this doesn't mean that the solutions to all problems are feasible, but stating the problem is a much better start than griping.

Re: hey monks
by Anonymous Monk on Apr 24, 2014 at 19:01 UTC
Re: hey monks
by InfiniteSilence (Curate) on Apr 24, 2014 at 19:42 UTC

    And the winner for the worst titled question on Perlmonks is...

    Celebrate Intellectual Diversity

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2023-06-09 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (35 votes). Check out past polls.

    Notices?