Please reply to the group so that others may answer also. :-) Your solution will return only the first 7 characters of the filename. My solution solution returns all characters after the last slash (first you used \ now you are using /) and before the first _ (underscore). Just keep this in mind.
You can break my solution up into three steps: 1) split the original filename on the directory separator into a list 2) take the last item in the list and split it on the underscore into another list 3) return the first item of the last list If that still didn't make sense, here's the code again: 1) (split /\\/, $FILENAME)[-1] Starting with the expression within the parentheses -- split /\\/, $FILENAME. This says split $FILENAME into a list. Every time you see a slash add to the list. 2) This turns "C:\Developer\view_local\local_nt\FDAFDSAFDSASDFA\ASDFDAFSASDF\NewProcess_da te_22-oct-2004.log" into a list containing the strings C: Developer view_local local_nt FDAFDSAFDSASDFA ASDFDAFSASDF NewProcess_date_22-oct-2004.log 3) Going back to the expression: (split /\\/, $FILENAME)[-1] The () reinforce that fact that the split is returning a list of items. [-1] says go to the last item. In this case that item is "NewProcess_date_22-oct-2004.log" 4) Which brings us to: (split /_/, (split /\\/, $FILENAME)[-1])[0] I just described what the inner split does, so we can simplify. That gives us: (split /_/, "NewProcess_date_22-oct-2004.log")[0] 5) This split does the same thing except now it is splitting on _. This turns "NewProcess_date_22-oct-2004.log" into: NewProcess date 22-oct-2004.log 6) The [0] says go to the first item in the list from 5). This happens to be "NewProcess". You're done! Please read: perldoc -f split perldoc -q "What is the difference between a list and an array?" Good luck, ZO -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, October 23, 2004 7:41 AM To: [EMAIL PROTECTED] Subject: RE: how the print the first 7 letter of file name Hi The problem resolved. I have confirmed my self ---------------------------------------- use File::Basename; $FILENAME="/Developer/view_local/local_nt/FDAFDSAFDSASDFA/ASDFDAFSASDF/NewPr ocess_date_22-oct-2004.log"; my $name = basename($FILENAME,'.log'); $name= substr($name, 0, 7); print $name ============================================= Thanks for info. by the way can you explain the meaning of this line my $file = (split /_/, (split /\\/, $FILENAME)[-1])[0]; I am not clear. Kindly -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>