in reply to Re^2: Write in files
in thread Write in files

I have a few questions to your code. what exactly does the code  $verzeichnis{lc $name} = $telefonnummer; and
if( defined $verzeichnis{lc $name2} ) { print $new ";+49".$verzeichnis{lc $name2}; }
does?

I haven't worked with  defined and  lc yet...

Thanks for your efforts!

Replies are listed 'Best First'.
Re^4: Write in files
by hdb (Monsignor) on Nov 18, 2013 at 11:02 UTC

    defined checks whether or not a key is defined in a hash, in this context it will return true if the name was found in your file 1. lc turns a string into lower case, adding a bit of robustness to the code (I assumed you wanted to do case insensitive matching).

    Generally, there is excellent documentation at http://perldoc.perl.org should you be unfamiliar with a specific function.

    UPDATE: It seems I was a bit tired when writing in this thread. While defined does the job, one really should be using exists. Apologies! A simple introduction into hashes can be found here http://www.tutorialspoint.com/perl/perl_hashes.htm but googling "perl hash" will lead to many more good hits.

      what will happen if the define check will be false? The line wouldn't be written to the new file, right?

      what does the Connection from  $Verzeichnis{lc $name2}; exactly do? I want to understand all parts of the script :)

        The line from file 2 will be written before the check! If the check is true, the phone number will be appended. Finally, a newline is added independently of the outcome of the check.

        In order to understand $verzeichnis{...} you would need to read up on hashes in Perl.