CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Wildcards

 



karldh
Deleted

Apr 11, 2001, 5:49 AM

Post #1 of 5 (742 views)
Wildcards Can't Post

Hi can someone please help me, I have written a perl script that adds 2 new lines to an .INI files , but what I need to do is get this script to do this to multiple .INI files that in in a DIR, D:\profiles\wilcard needed here\windows\p2001.ini, if I specify a finite path to 1 dir it works but I have 2000 in separate dir's, so is there a wilcard like *.* that would work, have tried ^.*\..*$, but no joy, full script is below thanks Karl
#! /usr/bin/perl


@filelist = ("??????????/WINDOWS/P2001.INI");

foreach $file (@filelist) {

open(INFILE,"< $file") || die "Could not open file $file\n";

@filelines = <INFILE>;
close INFILE;

open(OUTFILE,"> $file") || die "Could not open $file\n";

foreach $line (@filelines) {
if ($line =~ /TITLE=LOGAŽ2001/) {
print OUTFILE $line;
print OUTFILE "ADMINBMP= ->neu\n","LOGABMP= ->neu\n";
} else { print OUTFILE $line;}
}
close OUTFILE;
}



freddo
User

Apr 11, 2001, 6:11 AM

Post #2 of 5 (740 views)
Re: Wildcards [In reply to] Can't Post

Hello Karldh,

try to use instead:
@filelist = <D:/profiles/*/windows/p2001.ini>;

I just tested this:

Code
administrator@COKE ~ 
$ touch html/xxx tmp/xxx tst/xxx

administrator@COKE ~
$ perl -e 'print join "\n", <*/xxx>;'
html/xxx
src/xxx
tmp/xxx
tst/xxx

administrator@COKE ~
$



i hope this helps...
freddo


; -----
Real Programmers dont need class,
They just have style...


karldh
Deleted

Apr 11, 2001, 6:52 AM

Post #3 of 5 (735 views)
Re: Wildcards [In reply to] Can't Post

Hi freddo,
thanks for the help, tried but it did not work does not recognise * as a wildcard, am working in a Win32 env if this makes a difference
regards
Karl



Jean
User


Apr 11, 2001, 7:49 AM

Post #4 of 5 (733 views)
Re: Wildcards [In reply to] Can't Post

In general freddo's solution works and the only reason I can see for its failure is incorrect number of slashes(/) per number of directories, e.g.
@filelist = <C:/WinNT/Profiles/*/windows/p2001.ini>;
will match
C:/WinNT/Profiles/dir1/windows/p2001.ini
but will not match
C:/WinNT/Profiles/dir1/dir2/windows/p2001.ini

In case you're using backslash(\), make sure you're using double backslash (\\) every time you want to use one.

Jean Spector
QA Engineer @ Extent Technologies, Ltd.
mage@lycosmail.com


freddo
User

Apr 11, 2001, 10:18 AM

Post #5 of 5 (728 views)
Re: Wildcards [In reply to] Can't Post

Yes, Jean is right, only the number of slashes per folders could be wrong... or else i tried that on win2000 with CygWin a unix environment for windows, so the command line was:

Code
perl -e 'print join "\n", <*/xxx>;'


for MS-DOS command.com or cmd.exe, it turns to be:

Code
perl -e "print join \"\n\d\", <*/xxx>;"


and for JPSoft's 4DOS and 4NT, it is:

Code
perl -e "print join <Ctrl-X>"\n\d<Ctrl-X>", <*/xxx>;"


i hope this will work, else check perldoc perlfaq3 (Why don't Perl one-liners work on my DOS/Mac/VMS system?) OR check this and this about file globs OR if it's not about globbing, try to check the module File::Find (default installation).

freddo


; -----
Real Programmers dont need class,
They just have style...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives