(Re-directed to the list)
On 08/12/2006 05:44 AM, [EMAIL PROTECTED] wrote:
Hi Mumia,
Thanks for your tip, that's a good one ... just need to make
some more
modifications as below:
if ($path =~ m/\Q$ini{"SOURCE_DIR$count"}\E/i) {
$TARGET_DIR = $ini{"TARGET_DIR$count"};
} else {
$TARGET_DIR = $DEFAULT_TARGET_DIR;
}
Am not an advanced Perl programmer but am slowly getting
very interested with
it, can you please kindly explain what the ones in the your
code does or
whether I understand them correctly as such
This piece of code enclose the string FTP_USER to
TARGET_DIR2=C:\Dir2 in
single quote and assign to $data?
Yes. Naturally, in your own code, you would read all of the
data from the INI file and assign it to $data, perhaps like so:
$data = join ('',<INIFILE>);
my $data = q{
FTP_USER=FTPUser
FTP_PASSWORD=FTPUser
FTP_MODE=binary
FTP_TARGET_SERVER=FTPSERVER
FTP_ACTION_DIR=C:\FtpAction
FTP_LOGPATH=C:\Temp
NUM_OF_DIRS=2
DEFAULT_TARGET_DIR=C:\Temp
SOURCE_DIR1=D:\Study\Perl\MyFtp
SOURCE_DIR2=D:\Study\Perl
TARGET_DIR1=C:\Dir1
TARGET_DIR2=C:\Dir2
};
What does these two lines of code do?
$data =~ s/^\s+|\s+\z//;
The line above strips off spaces at the beginning and end of
$data. Read "perldoc perlre"; I should've split it into two
statements for clarity:
$data =~ s/^\s+//;
$data =~ s/\s+\z//;
my %ini = split /[ \n=]+/, $data;
The line above splits $data, and it splits on spaces, newlines
or equal signs. The resulting array is a bunch of NAME VALUE
pairs, and that's perfect for assigning to a hash (%ini).
I know the first one does a search and replace but I can't
work out what pattern
it is replacing. The second one creates an array %ini out
of $data with
[space][return line][=][spaces] as the delimiter?
Am I correct?
%ini is a hash, not an array.
And this line
print Dumper(\%ini);
prints the content of the array %ini?
Yes
I just want to know whether I understand it correctly or
not. Thanks in
advance!
You're welcome.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>