LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2008, 02:03 AM   #1
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
How to check if an array is empty in Perl (newbie question)


Hello,
To do this, can I do this?:

if (@ary = ""),

or is something more needed?
 
Old 11-28-2008, 02:13 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
you can check for the length of the array.
 
Old 11-28-2008, 02:24 AM   #3
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
how do I do that?
 
Old 11-28-2008, 02:37 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
perldoc -f length
read carefully what it says.
 
Old 11-28-2008, 03:26 AM   #5
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Quote:
Originally Posted by resetreset View Post
Hello,
To do this, can I do this?:

if (@ary = ""),

or is something more needed?
Not quite. In scalar context, an array evaluates to its length. Therefore, you could say

Code:
if (@ary == 0)
You could also use this

Code:
if (!@ary)
since 0 is considered false. Or this

Code:
if ($#ary < 0)
or even

Code:
if (scalar(@ary) == 0)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl .check if data are exist in the array before adding new data ufmale Programming 12 07-14-2010 05:26 AM
[perl] copying an array element into another array s0l1dsnak3123 Programming 2 05-17-2008 01:47 AM
Perl: Array spliting, sorry another question :( PB0711 Programming 3 07-27-2006 01:38 PM
Perl array (newbie) question Seventh Programming 5 09-02-2004 12:11 PM
PERL: Size of an array of an Array inspleak Programming 2 03-10-2004 02:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration