Sponsored Content
Top Forums Shell Programming and Scripting perl - how come this script works? Post 302136370 by cbkihong on Monday 17th of September 2007 10:27:45 AM
Old 09-17-2007
Quote:
Originally Posted by mjays
but in the code above @contents isn't defined.
It is implicitly created for you. In this case, it is an array with no elements inside. You can always put

@contents = ();

at the top of the script to make your intent specific (I usually do this), but it is not required.

To explicitly declare it as a lexical is in fact a better practice, so that becomes

my @contents = ();

As for your posted program, it is a very simple one (I think you have stated it yourself). If you have any specific queries, feel free to follow-up.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script works with bash 3.0 but not 3.2.

Hello, So my knowledge of bash scripting is not that great and I have been trying to solve this problem on my own for awhile to no avail. Here's the error I get when running it with an OS that uses bash 3.2.x: testagain.sh: line 10: *-1: syntax error: operand expected (error token is... (2 Replies)
Discussion started by: forkandspoon
2 Replies

2. Shell Programming and Scripting

perl oneliner not works .pl script

I am trying to take first 3 columns in a file which matches the word "abc", but i am getting the below error, <error> Global symbol "@F" requires explicit package name at ./new.pl </error> whereas when i give the below,grep abc /home/test/file.txt|perl -lane 'print \"$F $F $F\" in unix prompt... (4 Replies)
Discussion started by: anspks
4 Replies

3. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

4. Shell Programming and Scripting

Script works but doesn't?

Hi everyone I'm new here so and I'm just starting to learn a bit of Solaris and I'm working on repairing 10 year old scripts for our system here at work. When I execute the commands at my prompt everything go's through smooth. I'm using gedit to edit my code because I'm still getting used to the... (4 Replies)
Discussion started by: 82280zx
4 Replies

5. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

6. Shell Programming and Scripting

Script almost works... one error

Helo, i have written a bash script for running my calculations. anyway, according to shellcheck the error is somewhere in the while loop or in the if condition. so the idea of this script is: submit a job with a name. while it is in the queue it has a job ID number. after the job is done i... (2 Replies)
Discussion started by: carborane
2 Replies

7. Shell Programming and Scripting

Perl error in batch command but works one at a time

In the below perl executes if one file is processed perfect. However, when multiple files are processed in batch which is preferred I get the below error that I can not seem to fix it as the '' necessary for the command to execute, but seem to only work for one -arg option. Thank you :). ... (2 Replies)
Discussion started by: cmccabe
2 Replies

8. Shell Programming and Scripting

Need to understand how the line in perl program works as shell commend

I have a file with two line, one is header, the other actual value: TYPCD|ETID2|ETID|LEG ID|PTYP|PTYP SUB|TRD STATUS|CXL REASON|CACT|CACTNM|ENCD|ENC D NM|TRDR|ASDT|TRDT|MTDT|STDT|LS|SECID|SECID TYP|SECNM|PAR|STCC|MARKET PRICE|DIS MARKET PRICE|MARKET PRICE CURRENCY|SRC OF SETTLEMENT... (2 Replies)
Discussion started by: digioleg54
2 Replies

9. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

10. Shell Programming and Scripting

Script works, but I think it could be better and faster

Hi All, I'm new to the forum and to bash scripting. I did some stuff with VB.net, Batch, and VBScripting in the past, but because I shifted over to Linux, I am learning to script in Bash at this moment. So bear with me if I seem to script like a newbie, that's just because I am ;-) OK, I... (9 Replies)
Discussion started by: cornelvis
9 Replies
XATTR_NAME_WITH_FLAGS(3)				   BSD Library Functions Manual 				  XATTR_NAME_WITH_FLAGS(3)

NAME
xattr_preserve_for_intent, xattr_name_with_flags, xattr_name_without_flags, xattr_flags_from_name, xattr_intent_with_flags LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <xattr_flags.h> int xattr_preserve_for_intent(const char *, xattr_operation_intent_t); char * xattr_name_with_flags(const char *, xattr_flags_t); char * xattr_name_without_flags(const char *); xattr_flags_t xattr_flags_from_name(const char *); int xattr_intent_with_flags(xattr_operation_intent_t, xattr_flags_t); DESCRIPTION
These functions are used in conjunction with copying extended attributes from one file to another. Various types of copying (an "intent") check flags to determine which is allowed or not. The xattr_name_with_flags() function returns an extended attribute name with the appropriate flags encoded as a string; the xattr_name_without_flags() undoes this, giving the name of the extended attribute without the flags encoding. The slight inverse of that is xattr_flags_from_name(), which will return the flags encoded in a name. The values returned by xattr_name_with_flags() and xattr_name_without_flags() are allocated using malloc(3), and should be released by the caller, using free(3). These functions also have an internal table of pre-defined names, maintained by the operating system. The function xattr_intent_with_flags() will return 0 if the flags argument indicates it should not be preserved for the given intent, or 1 if it should. The function xattr_preserve_for_intent() combines the functions above, and will return zero if the named extended attribute should be pre- served during a copy for the given intent. INTENT
The type is an integral type, which is used to indicate what the intent for the operation is. The following intent values are defined: XATTR_OPERATION_INTENT_COPY Indicates that the intent is to simply copy from the source to the destination. E.g., with cp. Most extended attributes should generally be preserved in this case. XATTR_OPERATION_INTENT_SAVE Indicates that intent is to perform a save (perhaps as in a "safe save"). This differs from a copy in that the content may be changing; the destination may be over-writing or replacing the source, and some extended attributes should not be preserved during this process. XATTR_OPERATION_INTENT_SHARE Indicates that the intent is to share, or export, the object. For example, saving as an attachment in an email message, or placing in a public folder. Sensitive information should probably not be preserved in this case. XATTR_OPERATION_INTENT_SYNC Indicates that the intent is to sync the object to a service like iCloud. FLAGS
Various flags are defined by the type the currently-defined values for this are XATTR_FLAG_NO_EXPORT This indicates that the extended attribute should not be exported, or shared. This is used with XATTR_OPERATION_INTENT_SHARE. XATTR_FLAG_CONTENT_DEPENDENT This indicates that the extended attribute is tied to the contents of the file (or vice versa), such that it should be re-created when the contents are changed. A checksum, for example, should not be copied, and would thus be marked with this flag. XATTR_FLAG_NEVER_PRESERVE This indicates that the extended attribute should never be copied from a source object to a destination, no matter what the given intent is. XATTR_FLAG_SYNCABLE This indicates that the extended attribute should be copied when the file is synced on services like iCloud. Sync services tends to want the metadata synced to be kept to a bare minimum, and may enforce additional restrictions on the acceptable size and number of extended attributes. EXAMPLE
The following example is a simple function that, given an extended attribute name and an operation intent, will return whether or not the extended attribute should be copied. (This essentially does what xattr_preserve_for_intent() does.) int ShouldCopyEA(const char *eaName, xattr_operation_intent_t intent) { xattr_flags_t flags = xattr_flags_from_name(eaName); return xattr_intent_with_flags(intent, flags); } HISTORY
These functions first appeared in Mac OS in 2013. BSD
December 21, 2016 BSD
All times are GMT -4. The time now is 02:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy