{
    "mode": "perldoc",
    "parameter": "find",
    "section": "-q",
    "url": "https://www.chedong.com/phpMan.php/perldoc/find/json",
    "generated": "2026-06-11T00:41:08Z",
    "sections": {
        "Found in /usr/share/perl/5.34/pod/perlfaq3.pod": {
            "content": "How do I find which modules are installed on my system?\nFrom the command line, you can use the \"cpan\" command's \"-l\" switch:\n\n$ cpan -l\n\nYou can also use \"cpan\"'s \"-a\" switch to create an autobundle file that\n\"CPAN.pm\" understands and can use to re-install every module:\n\n$ cpan -a\n\nInside a Perl program, you can use the ExtUtils::Installed module to\nshow all installed distributions, although it can take awhile to do its\nmagic. The standard library which comes with Perl just shows up as\n\"Perl\" (although you can get those with Module::CoreList).\n\nuse ExtUtils::Installed;\n\nmy $inst    = ExtUtils::Installed->new();\nmy @modules = $inst->modules();\n\nIf you want a list of all of the Perl module filenames, you can use\nFile::Find::Rule:\n\nuse File::Find::Rule;\n\nmy @files = File::Find::Rule->\nextras({follow => 1})->\nfile()->\nname( '*.pm' )->\nin( @INC )\n;\n\nIf you do not have that module, you can do the same thing with\nFile::Find which is part of the standard library:\n\nuse File::Find;\nmy @files;\n\nfind(\n{\nwanted => sub {\npush @files, $File::Find::fullname\nif -f $File::Find::fullname && /\\.pm$/\n},\nfollow => 1,\nfollowskip => 2,\n},\n@INC\n);\n\nprint join \"\\n\", @files;\n\nIf you simply need to check quickly to see if a module is available, you\ncan check for its documentation. If you can read the documentation the\nmodule is most likely installed. If you cannot read the documentation,\nthe module might not have any (in rare cases):\n\n$ perldoc Module::Name\n\nYou can also try to include the module in a one-liner to see if perl\nfinds it:\n\n$ perl -MModule::Name -e1\n\n(If you don't receive a \"Can't locate ... in @INC\" error message, then\nPerl found the module name you asked for.)\n",
            "subsections": []
        },
        "Found in /usr/share/perl/5.34/pod/perlfaq4.pod": {
            "content": "How do I find the day or week of the year?\nThe day of the year is in the list returned by the \"localtime\" function.\nWithout an argument \"localtime\" uses the current time.\n\nmy $dayofyear = (localtime)[7];\n\nThe POSIX module can also format a date as the day of the year or week\nof the year.\n\nuse POSIX qw/strftime/;\nmy $dayofyear  = strftime \"%j\", localtime;\nmy $weekofyear = strftime \"%W\", localtime;\n\nTo get the day of year for any date, use POSIX's \"mktime\" to get a time\nin epoch seconds for the argument to \"localtime\".\n\nuse POSIX qw/mktime strftime/;\nmy $weekofyear = strftime \"%W\",\nlocaltime( mktime( 0, 0, 0, 18, 11, 87 ) );\n\nYou can also use Time::Piece, which comes with Perl and provides a\n\"localtime\" that returns an object:\n\nuse Time::Piece;\nmy $dayofyear  = localtime->yday;\nmy $weekofyear = localtime->week;\n\nThe Date::Calc module provides two functions to calculate these, too:\n\nuse Date::Calc;\nmy $dayofyear  = DayofYear(  1987, 12, 18 );\nmy $weekofyear = WeekofYear( 1987, 12, 18 );\n\nHow do I find the current century or millennium?\nUse the following simple functions:\n\nsub getcentury    {\nreturn int((((localtime(shift || time))[5] + 1999))/100);\n}\n\nsub getmillennium {\nreturn 1+int((((localtime(shift || time))[5] + 1899))/1000);\n}\n\nOn some systems, the POSIX module's \"strftime()\" function has been\nextended in a non-standard way to use a %C format, which they sometimes\nclaim is the \"century\". It isn't, because on most such systems, this is\nonly the first two digits of the four-digit year, and thus cannot be\nused to determine reliably the current century or millennium.\n\nHow can I compare two dates and find the difference?\n(contributed by brian d foy)\n\nYou could just store all your dates as a number and then subtract. Life\nisn't always that simple though.\n\nThe Time::Piece module, which comes with Perl, replaces localtime with a\nversion that returns an object. It also overloads the comparison\noperators so you can compare them directly:\n\nuse Time::Piece;\nmy $date1 = localtime( $sometime );\nmy $date2 = localtime( $someothertime );\n\nif( $date1 < $date2 ) {\nprint \"The date was in the past\\n\";\n}\n\nYou can also get differences with a subtraction, which returns a\nTime::Seconds object:\n\nmy $datediff = $date1 - $date2;\nprint \"The difference is \", $datediff->days, \" days\\n\";\n\nIf you want to work with formatted dates, the Date::Manip, Date::Calc,\nor DateTime modules can help you.\n\nHow can I find the Julian Day?\n(contributed by brian d foy and Dave Cross)\n\nYou can use the Time::Piece module, part of the Standard Library, which\ncan convert a date/time to a Julian Day:\n\n$ perl -MTime::Piece -le 'print localtime->julianday'\n2455607.7959375\n\nOr the modified Julian Day:\n\n$ perl -MTime::Piece -le 'print localtime->mjd'\n55607.2961226851\n\nOr even the day of the year (which is what some people think of as a\nJulian day):\n\n$ perl -MTime::Piece -le 'print localtime->yday'\n45\n\nYou can also do the same things with the DateTime module:\n\n$ perl -MDateTime -le'print DateTime->today->jd'\n2453401.5\n$ perl -MDateTime -le'print DateTime->today->mjd'\n53401\n$ perl -MDateTime -le'print DateTime->today->doy'\n31\n\nYou can use the Time::JulianDay module available on CPAN. Ensure that\nyou really want to find a Julian day, though, as many people have\ndifferent ideas about Julian days (see\n<http://www.hermetic.ch/calstud/jdn.htm> for instance):\n\n$  perl -MTime::JulianDay -le 'print localjulianday( time )'\n55608\n\nHow do I find yesterday's date?\n(contributed by brian d foy)\n\nTo do it correctly, you can use one of the \"Date\" modules since they\nwork with calendars instead of times. The DateTime module makes it\nsimple, and give you the same time of day, only the day before, despite\ndaylight saving time changes:\n\nuse DateTime;\n\nmy $yesterday = DateTime->now->subtract( days => 1 );\n\nprint \"Yesterday was $yesterday\\n\";\n\nYou can also use the Date::Calc module using its \"TodayandNow\"\nfunction.\n\nuse Date::Calc qw( TodayandNow AddDeltaDHMS );\n\nmy @datetime = AddDeltaDHMS( TodayandNow(), -1, 0, 0, 0 );\n\nprint \"@datetime\\n\";\n\nMost people try to use the time rather than the calendar to figure out\ndates, but that assumes that days are twenty-four hours each. For most\npeople, there are two days a year when they aren't: the switch to and\nfrom summer time throws this off. For example, the rest of the\nsuggestions will be wrong sometimes:\n\nStarting with Perl 5.10, Time::Piece and Time::Seconds are part of the\nstandard distribution, so you might think that you could do something\nlike this:\n\nuse Time::Piece;\nuse Time::Seconds;\n\nmy $yesterday = localtime() - ONEDAY; # WRONG\nprint \"Yesterday was $yesterday\\n\";\n\nThe Time::Piece module exports a new \"localtime\" that returns an object,\nand Time::Seconds exports the \"ONEDAY\" constant that is a set number of\nseconds. This means that it always gives the time 24 hours ago, which is\nnot always yesterday. This can cause problems around the end of daylight\nsaving time when there's one day that is 25 hours long.\n\nYou have the same problem with Time::Local, which will give the wrong\nanswer for those same special cases:\n\n# contributed by Gunnar Hjalmarsson\nuse Time::Local;\nmy $today = timelocal 0, 0, 12, ( localtime )[3..5];\nmy ($d, $m, $y) = ( localtime $today-86400 )[3..5]; # WRONG\nprintf \"Yesterday: %d-%02d-%02d\\n\", $y+1900, $m+1, $d;\n\nHow do I find matching/nesting anything?\nTo find something between two single characters, a pattern like\n\"/x([^x]*)x/\" will get the intervening bits in $1. For multiple ones,\nthen something more like \"/alpha(.*?)omega/\" would be needed. For nested\npatterns and/or balanced expressions, see the so-called (?PARNO)\nconstruct (available since perl 5.10). The CPAN module Regexp::Common\ncan help to build such regular expressions (see in particular\nRegexp::Common::balanced and Regexp::Common::delimited).\n\nMore complex cases will require to write a parser, probably using a\nparsing module from CPAN, like Regexp::Grammars, Parse::RecDescent,\nParse::Yapp, Text::Balanced, or Marpa::R2.\n\nHow do I find the soundex value of a string?\n(contributed by brian d foy)\n\nYou can use the \"Text::Soundex\" module. If you want to do fuzzy or close\nmatching, you might also try the String::Approx, and Text::Metaphone,\nand Text::DoubleMetaphone modules.\n\nHow do I find the first array element for which a condition is true?\nTo find the first array element which satisfies a condition, you can use\nthe \"first()\" function in the List::Util module, which comes with Perl\n5.8. This example finds the first element that contains \"Perl\".\n\nuse List::Util qw(first);\n\nmy $element = first { /Perl/ } @array;\n\nIf you cannot use List::Util, you can make your own loop to do the same\nthing. Once you find the element, you stop the loop with last.\n\nmy $found;\nforeach ( @array ) {\nif( /Perl/ ) { $found = $; last }\n}\n\nIf you want the array index, use the \"firstidx()\" function from\n\"List::MoreUtils\":\n\nuse List::MoreUtils qw(firstidx);\nmy $index = firstidx { /Perl/ } @array;\n\nOr write it yourself, iterating through the indices and checking the\narray element at each index until you find one that satisfies the\ncondition:\n\nmy( $found, $index ) = ( undef, -1 );\nfor( $i = 0; $i < @array; $i++ ) {\nif( $array[$i] =~ /Perl/ ) {\n$found = $array[$i];\n$index = $i;\nlast;\n}\n}\n",
            "subsections": []
        },
        "Found in /usr/share/perl/5.34/pod/perlfaq7.pod": {
            "content": "How can I find out my current or calling package?\n(contributed by brian d foy)\n\nTo find the package you are currently in, use the special literal\n\"PACKAGE\", as documented in perldata. You can only use the special\nliterals as separate tokens, so you can't interpolate them into strings\nlike you can with variables:\n\nmy $currentpackage = PACKAGE;\nprint \"I am in package $currentpackage\\n\";\n\nIf you want to find the package calling your code, perhaps to give\nbetter diagnostics as Carp does, use the \"caller\" built-in:\n\nsub foo {\nmy @args = ...;\nmy( $package, $filename, $line ) = caller;\n\nprint \"I was called from package $package\\n\";\n);\n\nBy default, your program starts in package \"main\", so you will always be\nin some package.\n\nThis is different from finding out the package an object is blessed\ninto, which might not be the current package. For that, use \"blessed\"\nfrom Scalar::Util, part of the Standard Library since Perl 5.8:\n\nuse Scalar::Util qw(blessed);\nmy $objectpackage = blessed( $object );\n\nMost of the time, you shouldn't care what package an object is blessed\ninto, however, as long as it claims to inherit from that class:\n\nmy $isrightclass = eval { $object->isa( $package ) }; # true or false\n\nAnd, with Perl 5.10 and later, you don't have to check for an\ninheritance to see if the object can handle a role. For that, you can\nuse \"DOES\", which comes from \"UNIVERSAL\":\n\nmy $classdoesit = eval { $object->DOES( $role ) }; # true or false\n\nYou can safely replace \"isa\" with \"DOES\" (although the converse is not\ntrue).\n",
            "subsections": []
        },
        "Found in /usr/share/perl/5.34/pod/perlfaq8.pod": {
            "content": "How do I find out which operating system I'm running under?\nThe $^O variable ($OSNAME if you use \"English\") contains an indication\nof the name of the operating system (not its release number) that your\nperl binary was built for.\n\nHow do I find out if I'm running interactively or not?\n(contributed by brian d foy)\n\nThis is a difficult question to answer, and the best answer is only a\nguess.\n\nWhat do you really want to know? If you merely want to know if one of\nyour filehandles is connected to a terminal, you can try the \"-t\" file\ntest:\n\nif( -t STDOUT ) {\nprint \"I'm connected to a terminal!\\n\";\n}\n\nHowever, you might be out of luck if you expect that means there is a\nreal person on the other side. With the Expect module, another program\ncan pretend to be a person. The program might even come close to passing\nthe Turing test.\n\nThe IO::Interactive module does the best it can to give you an answer.\nIts \"isinteractive\" function returns an output filehandle; that\nfilehandle points to standard output if the module thinks the session is\ninteractive. Otherwise, the filehandle is a null handle that simply\ndiscards the output:\n\nuse IO::Interactive;\n\nprint { isinteractive } \"I might go to standard output!\\n\";\n\nThis still doesn't guarantee that a real person is answering your\nprompts or reading your output.\n\nIf you want to know how to handle automated testing for your\ndistribution, you can check the environment. The CPAN Testers, for\ninstance, set the value of \"AUTOMATEDTESTING\":\n\nunless( $ENV{AUTOMATEDTESTING} ) {\nprint \"Hello interactive tester!\\n\";\n}\n",
            "subsections": []
        },
        "Found in /usr/share/perl/5.34/pod/perlfaq9.pod": {
            "content": "How do I find the user's mail address?\nAsk them for it. There are so many email providers available that it's\nunlikely the local system has any idea how to determine a user's email\naddress.\n\nThe exception is for organization-specific email (e.g.\nfoo@yourcompany.com) where policy can be codified in your program. In\nthat case, you could look at $ENV{USER}, $ENV{LOGNAME}, and getpwuid($<)\nin scalar context, like so:\n\nmy $username = getpwuid($<)\n\nBut you still cannot make assumptions about whether this is correct,\nunless your policy says it is. You really are best off asking the user.\n\nHow do I find out my hostname, domainname, or IP address?\n(contributed by brian d foy)\n\nThe Net::Domain module, which is part of the Standard Library starting\nin Perl 5.7.3, can get you the fully qualified domain name (FQDN), the\nhost name, or the domain name.\n\nuse Net::Domain qw(hostname hostfqdn hostdomain);\n\nmy $host = hostfqdn();\n\nThe Sys::Hostname module, part of the Standard Library, can also get the\nhostname:\n\nuse Sys::Hostname;\n\n$host = hostname();\n\nThe Sys::Hostname::Long module takes a different approach and tries\nharder to return the fully qualified hostname:\n\nuse Sys::Hostname::Long 'hostnamelong';\n\nmy $hostname = hostnamelong();\n\nTo get the IP address, you can use the \"gethostbyname\" built-in function\nto turn the name into a number. To turn that number into the dotted\noctet form (a.b.c.d) that most people expect, use the \"inetntoa\"\nfunction from the Socket module, which also comes with perl.\n\nuse Socket;\n\nmy $address = inetntoa(\nscalar gethostbyname( $host || 'localhost' )\n);\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}