Jump to content

Recommended Posts

Hi there,

 

I am trying to fix a bug in a Perl script.

 

Can someone explain what the below code does/would do?

 

while (my $a = readdir(DIR)){

    if($a =~ m/(.+?)_(air)?port/ && $a !~ m/featured_(air)?port/ && $a !~ m/london_airport/i && $a !~ m/glasgow/ && $a !~ m/_opt/i){

        push(@dirs,$a);

    }

}

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/284066-perl-script-help/
Share on other sites

Your human-readable code would be something like this.

 

"While we can still read files from this directory, loop through them; then, if it matches the expression m/(.+?)_(air)?port/ but does not match the other ones, push the current file into the array 'dirs'."

Link to comment
https://forums.phpfreaks.com/topic/284066-perl-script-help/#findComment-1459021
Share on other sites

m/ is "multiline mode".  

https://courses.cs.washington.edu/courses/cse190m/12sp/cheat-sheets/php-regex-cheat-sheet.pdf

 

 

 

also, does the script mean if the files are broken/missing, it will revert to london_airport?


Not sure what you mean, either.  It will create a list (array) of dirnames that have to do with airports, but not featured airports or London airport, or Glasgow or any dir with "opt" in it, more or less. Edited by dalecosp
Link to comment
https://forums.phpfreaks.com/topic/284066-perl-script-help/#findComment-1459026
Share on other sites

Those expressions with m/(.+?)_/ and others are regular expressions.

The prefix m is for multiline mode, as dalecops pointed out previously.

 

There are many guides to understand regular expressions, but they are pretty complex subjects and even though I've been trying to for the past months, I haven't completely understood everything about them.

Link to comment
https://forums.phpfreaks.com/topic/284066-perl-script-help/#findComment-1459053
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.