Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

-type: -f: unknown type

by rickkar (Initiate)
on Oct 30, 2012 at 23:27 UTC ( #1001575=perlquestion: print w/replies, xml ) Need Help??
rickkar has asked for the wisdom of the Perl Monks concerning the following question:

in running the code below i get

amc-~$ perl

find: -type: -f: unknown type

need help in figuring out how to remedy

find: -type: -f: unknown type

#!/usr/bin/perl use strict; use warnings; use 5.010; use LWP::Simple; use File::Find; # for traversing directory and locating a part +icular file use File::Copy; use XML::Simple; # for parsing XML use JSON::Parse; # for parsing JSON format #use Data::Dumper qw(pp); use Data::Dumper; #use Data::Dump qw(pp); my $filepath_root = '/Users/karcichr/Downloads/Elsevier/fulltext/elsev +ier/historical/' || shift @ARGV; for( my @files = qx{find $filepath_root -name 'main.xml' -type -f} ) + # step (1+2) { my $ref = XMLin( $_ ); # step (3) { die "Showing first main.xml xml: ", pp( $ref ); # dump + $ref structure, so to learn where doi/title is } }

Replies are listed 'Best First'.
Re: -type: -f: unknown type
by space_monk (Chaplain) on Oct 31, 2012 at 03:01 UTC
    The simple answer is surely that it should be
    qx{find $filepath_root -name 'main.xml' -type f}
    Note the removal of the '-' before the 'f'. There may be better solutions than making a call to the shell though.....
Re: -type: -f: unknown type
by Anonymous Monk on Oct 30, 2012 at 23:37 UTC

    Why are you using qx instead of File::Find::find()?

    $ find2perl $filepath_root -name main.xml -type -f

    #! c:\perl\5.14.1\bin\MSWin32-x86-multi-thread\perl.exe -w eval 'exec c:\perl\5.14.1\bin\MSWin32-x86-multi-thread\perl.exe -S + $0 ${1+"$@"}' if 0; #$running_under_some_shell use strict; use File::Find (); # Set the variable $File::Find::dont_use_nlink if you're using AFS, # since AFS cheats. # for the convenience of &wanted calls, including -eval statements: use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; sub wanted; # Traverse desired filesystems File::Find::find({wanted => \&wanted}, $filepath_root); exit; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); /^main\.xml\z/s && (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ && print("$name\n"); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001575]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-06-19 18:37 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.