HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- perl - how to use a variable as part of a command
Operating System - HP-UX
1834029
Members
1911
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2004 10:05 AM
07-22-2004 10:05 AM
I'm trying to do something like this: a variable to hold the character > or < and then use the variable in the find command to control whether it finds mtime + or mtime -
for example:
use File::Find ();
sub find(&@) { &File::Find::find }
*name = *File::Find::name;
$DIRECTION = '>';
find{-f $_ && (int(-M _) $DIRECTION $DAYS) && unshift (@DEVnames,$name)}
"/tmp/";
foreach $FNAME (@DEVnames) {
print $FNAME;
}
But it blows up:
Scalar found where operator expected at ./tdir line 10, near ") $DIRECTION"
(Missing operator before $DIRECTION?)
Scalar found where operator expected at ./tdir line 10, near "$DIRECTION $DAYS"
(Missing operator before $DAYS?)
syntax error at ./tdir line 10, near ") $DIRECTION "
Execution of ./tdir aborted due to compilation errors.
- Thanks,
John
Solved! Go to Solution.
- Tags:
- Perl
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2004 10:09 AM
07-22-2004 10:09 AM
Re: perl - how to use a variable as part of a command
when I entered the example, I cut and pasted, but I left out where I set a value for $DAYS. Something like this:
$DAYS = 1;
- John
$DAYS = 1;
- John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2004 01:55 AM
07-23-2004 01:55 AM
Solution
Syntactically-
int(-M _) $DIRECTION $DAYS is not valid
You could use "eval"
eval(int(-M _) $DIRECTION $DAYS)
But it would have extra overhead to "compile" this line each time.
You could use "?" operator
$DIRECTION eq ">" ? int(-M _) > $DAYS : int(-M _) < $DAYS
HTH
-- Rod Hills
int(-M _) $DIRECTION $DAYS is not valid
You could use "eval"
eval(int(-M _) $DIRECTION $DAYS)
But it would have extra overhead to "compile" this line each time.
You could use "?" operator
$DIRECTION eq ">" ? int(-M _) > $DAYS : int(-M _) < $DAYS
HTH
-- Rod Hills
There be dragons...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2004 06:15 AM
07-23-2004 06:15 AM
Re: perl - how to use a variable as part of a command
Thanks Rod.
(I'm a little surprised there's not a more direct way of doing what I want; seems like with all the cool syntactic features of perl they'd have invented a way to do this...)
- John
(I'm a little surprised there's not a more direct way of doing what I want; seems like with all the cool syntactic features of perl they'd have invented a way to do this...)
- John
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP