Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

[OT] How to take only the links of files which has high prirority links using perl?

by finddata (Sexton)
on Mar 16, 2017 at 09:10 UTC ( #1184847=perlquestion: print w/replies, xml ) Need Help??

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

i have the following output.Now i like to print the highest priority files with its directory links have can i do it using perl?

Available Input directory structure:
html `-- DEMO |-- DEMO_.html |-- top | |-- DV | | |-- DEMO_top__DV_.html | | |-- rev1 | | | `-- DEMO_top_DV_rev1_.html | | `-- rev2 | | `-- DEMO_top_DV_rev2_.html
Expected:
html `-- DEMO |-- DEMO_.html |-- top | |-- DV | | |-- DEMO_top__DV_.html | | `-- rev2 | | `-- DEMO_top_DV_rev2_.html

1.depending upon the greatest number of filenames the directory should be linked with the file.

2.The above linux comamnd fails for me.Let me know how to do it with perl or linux.

my $location = $output_dir; open LOGFILE, $location; my $first_line = 1; my $max_id; while (<LOGFILE>) { if (/_(\d)+/) { if ($first_line) { $first_line = 0; $max_id = $1; } else { $max_id = $1 if ($1 > $max_id); } } }

Replies are listed 'Best First'.
Re: [OT] How to take only the links of files which has high prirority links using perl?
by marto (Archbishop) on Mar 16, 2017 at 09:13 UTC

    This isn't a Linux support site. You've already been told that this site is for helping people learn perl and address problems with their perl code. You seem be treating this as a code writing service which it is not. We are not here to do your job for you.

Re: [OT] How to take only the links of files which has high prirority links using perl?
by GotToBTru (Prior) on Mar 16, 2017 at 13:12 UTC

    File::Find is one way to search thru a directory structure; use it to find the file with the highest priority. Then just trace down $File::Find::dir, printing the directory contents as you go. Fancy formatting is left as an exercise for the student.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: [OT] How to take only the links of files which has high priority links using perl?
by hippo (Chancellor) on Mar 16, 2017 at 09:43 UTC
      i had added my code which i had tried.
Re: [OT] How to take only the links of files which has high prirority links using perl?
by 1nickt (Abbot) on Mar 16, 2017 at 11:43 UTC

    Your code captures and assigns to $max_id only the last one of the first group of digits found. I expect that's probably not what you wanted.

    perl -Mstrict -W -E 'say $1 if "hello 0 and 123 goodbye" =~ /(\d)+/;' 0
    $ perl -Mstrict -W -E 'say $1 if "hello and 123 goodbye" =~ /(\d)+/;' 3
    Perhaps you want:
    $ perl -Mstrict -W -E 'say $1 if "hello and 123 goodbye" =~ /(\d+)/;' 123

    Hope this helps!

    (Update: show suggested fix and additional failing example)

    The way forward always starts with a minimal test.
      Could you please elaborate by some loops.
        What does that mean by some English?
Re: [OT] How to take only the links of files which has high prirority links using perl?
by LanX (Archbishop) on Mar 16, 2017 at 09:27 UTC
    I'm curious
    • Do you notice you are getting down votes?
    • Do you wonder why?

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      code which i tried is added with the question
        Do you know this doesn't answer my questions?

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2020-01-28 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?