Sponsored Content
Top Forums Shell Programming and Scripting Don't understand AWK asort behaviour Post 302575917 by jgilot on Wednesday 23rd of November 2011 08:21:29 AM
Old 11-23-2011
PHP Don't understand AWK asort behaviour

Hello,

I have the following script :

Code:
BEGIN {
print "1 ***";
  split("abc",T,""); 
  T[5]="e";
  T[26]="z";
  T[25]="y";
  for (i in T) printf("%i:%s ",i,T[i]);  print "";
  for (i=1; i<=length(T); i++) printf(T[i]); print ""

print "2 ***";
  asort(T,U);
  for (i in U) printf("%i:%s ",i,U[i]);  print "";
  for (i=1; i<=length(U); i++) printf(U[i]); print ""
}

and I don't understand the line following 2*** in the resulting display :

Code:
$ awk -f tst
1 ***
26:z 5:e 1:a 2:b 25:y 3:c 
abceyz
2 ***
26:z 17: 4: 18: 5: 19: 6: 7: 8: 9: 10: 20: 11: 21:a 12: 22:b 13: 23:c 14: 1: 24:e 15: 2: 25:y 16: 3: 
abceyz

I thought the result should have been : 1:a 2:b 3:c 4:e 5:y 6:z.

Where I am wrong ?
 

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

don't understand the unix script

if {"$my_ext_type" = MAIN]; then cd $v_sc_dir Filex.SH $v_so_dir\/$v_fr_file Can somebody tell me what does this suggest. I am pretty new to unix and I am getting confused. What i understood from here is If we have a file extension name as MAIN which we have then we change the directory to... (1 Reply)
Discussion started by: pochaman
1 Replies

2. Solaris

I don`t understand how It work (about startup script)?

Hi all. The startup script in /usr/local/bin. After user login the script run an application. Iwould in the same way run the another application. How to make It similar? Where I must to look? Regards. (3 Replies)
Discussion started by: wolfgang
3 Replies

3. Shell Programming and Scripting

Don't understand how RS functions in awk

I learn using RS in awk to extract portion of file in this forum which is wonderful solution to the problem. However, I don't understand how exactly it operates. I don't quite understand the mechanism behind how searching for /DATA2/ can result in extracting the whole section under "DATA2" ... (3 Replies)
Discussion started by: joe228
3 Replies

4. Homework & Coursework Questions

I don't understand some basics..

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1)find all lines in file ,myf that contain all the words cat dog and mouse in any order and start with the letter... (1 Reply)
Discussion started by: cudders
1 Replies

5. UNIX for Dummies Questions & Answers

Another Simple BASH command I don't understand. Help?

I have a text file called file1 which contains the text: "ls -l" When I enter this command: bash < file1 > file1 file1 gets erased. However if I enter this command: bash < file1 > newfile the output from "ls -l" is stored in newfile. My question is why doesn't file1's text ("ls -l") get... (3 Replies)
Discussion started by: phunkypants
3 Replies

6. Shell Programming and Scripting

Perl syntax that I don't understand.

I'm just trying to confirm that I understand someone's code correctly. If someone has code that says: $foo ||= mysub(); I'm assuming that it means if $foo is nothing or undef, then assign it some value via mysub(). If I'm wrong on this, please let me know. Also, what's the difference... (4 Replies)
Discussion started by: mrwatkin
4 Replies

7. UNIX for Dummies Questions & Answers

trying to compile and don't understand error message

this is my program i am trying to compile /* filedata -- display information about a file */ #include <stdlib.h> #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> /* * use octarray for determing * if permission bits set */ static short octarray = {0400, 0200, 0100,... (2 Replies)
Discussion started by: heywoodfloyd
2 Replies

8. UNIX for Dummies Questions & Answers

I don't understand conditions :(

Hi there, I have a very general question. I'm rather new to (bash) shell scripting and I don't understand how conditions work... I've read numerous tutorials but I don't get it. I really don't. Sometime what I do works, sometime it doesn't and that's frustating. So what's the actual difference... (0 Replies)
Discussion started by: hypsis
0 Replies
CORE(3pm)						 Perl Programmers Reference Guide						 CORE(3pm)

NAME
CORE - Namespace for Perl's core routines SYNOPSIS
BEGIN { *CORE::GLOBAL::hex = sub { 1; }; } print hex("0x50")," "; # prints 1 print CORE::hex("0x50")," "; # prints 80 CORE::say "yes"; # prints yes BEGIN { *shove = &CORE::push; } shove @array, 1,2,3; # pushes on to @array DESCRIPTION
The "CORE" namespace gives access to the original built-in functions of Perl. The "CORE" package is built into Perl, and therefore you do not need to use or require a hypothetical "CORE" module prior to accessing routines in this namespace. A list of the built-in functions in Perl can be found in perlfunc. For all Perl keywords, a "CORE::" prefix will force the built-in function to be used, even if it has been overridden or would normally require the feature pragma. Despite appearances, this has nothing to do with the CORE package, but is part of Perl's syntax. For many Perl functions, the CORE package contains real subroutines. This feature is new in Perl 5.16. You can take references to these and make aliases. However, some can only be called as barewords; i.e., you cannot use ampersand syntax (&foo) or call them through references. See the "shove" example above. These subroutines exist for all keywords except the following: "__DATA__", "__END__", "and", "cmp", "default", "do", "dump", "else", "elsif", "eq", "eval", "for", "foreach", "format", "ge", "given", "goto", "grep", "gt", "if", "last", "le", "local", "lt", "m", "map", "my", "ne", "next", "no", "or", "our", "package", "print", "printf", "q", "qq", "qr", "qw", "qx", "redo", "require", "return", "s", "say", "sort", "state", "sub", "tr", "unless", "until", "use", "when", "while", "x", "xor", "y" Calling with ampersand syntax and through references does not work for the following functions, as they have special syntax that cannot always be translated into a simple list (e.g., "eof" vs "eof()"): "chdir", "chomp", "chop", "defined", "delete", "each", "eof", "exec", "exists", "keys", "lstat", "pop", "push", "shift", "splice", "split", "stat", "system", "truncate", "unlink", "unshift", "values" OVERRIDING CORE FUNCTIONS
To override a Perl built-in routine with your own version, you need to import it at compile-time. This can be conveniently achieved with the "subs" pragma. This will affect only the package in which you've imported the said subroutine: use subs 'chdir'; sub chdir { ... } chdir $somewhere; To override a built-in globally (that is, in all namespaces), you need to import your function into the "CORE::GLOBAL" pseudo-namespace at compile time: BEGIN { *CORE::GLOBAL::hex = sub { # ... your code here }; } The new routine will be called whenever a built-in function is called without a qualifying package: print hex("0x50")," "; # prints 1 In both cases, if you want access to the original, unaltered routine, use the "CORE::" prefix: print CORE::hex("0x50")," "; # prints 80 AUTHOR
This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007. SEE ALSO
perlsub, perlfunc. perl v5.18.2 2013-11-04 CORE(3pm)
All times are GMT -4. The time now is 11:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy